CodeIgniter Forums
Can't remove index.php from the URL - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Can't remove index.php from the URL (/showthread.php?tid=19028)

Pages: 1 2


Can't remove index.php from the URL - El Forum - 05-25-2009

[eluser]chotz[/eluser]
I tried all the solutions posted in this forum
for removing index.php from the URL,but nothing seems to
work for me.

1) I used the the following .htaccess file:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

2) The modified config.php
changed
$config['index_page'] = "index.php";
to
$config['index_page'] = "";

3) activated mod_rewrite in Apache server.

4) saved the .htaccess file in htdocs folder.

I still can't get this to work.

Please help!


Can't remove index.php from the URL - El Forum - 05-25-2009

[eluser]TheFuzzy0ne[/eluser]
Try the different URI protocols in your config.php


Can't remove index.php from the URL - El Forum - 05-25-2009

[eluser]chotz[/eluser]
I tried all the options in config.php it doesn't work


i followed the instruction from :
http://www.danielwmoore.com/remove_index_from_codeigniter
and here is my new .htaccess file
(my applications is in /htdocs/system/application/controller/GameDev/
and my server is on windows)


Options -Indexes

Options -MultiViews
DirectoryIndex index.php


<IfModule mod_rewrite.so>

RewriteEngine on

RewriteBase /GameDev/


#RewriteCond %{REQUEST_FILENAME} !index.php
#RewriteRule (.*)\.php$ index.php/$1


RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

#RewriteRule ^(.*)$ index.php?/$1 [NC,L,QSA]
RewriteRule ^(.*)$ index.php/$1 [NC,L,QSA]

#RewriteRule ^(.*)$ CI_Application/index.php?/$1 [NC,L,QSA]
#RewriteRule ^(.*)$ CI_Application/index.php/$1 [NC,L,QSA]

</IfModule>

#-------------------------------------------------------------------------------
# If Mod_rewrite is NOT installed go to index.php
# Remember to use mod_rewrite.c for Linux and mod_rewrite.so for Windows.
#-------------------------------------------------------------------------------
<IfModule !mod_rewrite.c>
#<IfModule !mod_rewrite.so>
ErrorDocument 404 index.php
</IfModule>


Could somebody let me know if there is anything wrong with this file? considering that
i have my controller php files in /htdocs/system/application/Controller/GameDev

Also where should i place my .htaccess file. Right now i have placed it in /htdocs/ folder


Can't remove index.php from the URL - El Forum - 05-26-2009

[eluser]Daniel Moore[/eluser]
Place the .htaccess file in the folder where your "index.php" file is located for CodeIgniter.

Did you try both options with and without the question mark for the RewriteRule? I noticed you're using the one without the question mark.

Also, since you have your setup in a "subdirectory" of the web root as evidenced by "RewriteBase /GameDev/" then you need to find the following:

Code:
#RewriteRule ^(.*)$ index.php?/$1 [NC,L,QSA]
  RewriteRule ^(.*)$ index.php/$1 [NC,L,QSA]

  #RewriteRule ^(.*)$ CI_Application/index.php?/$1 [NC,L,QSA]
  #RewriteRule ^(.*)$ CI_Application/index.php/$1 [NC,L,QSA]

And change it to:
Code:
#RewriteRule ^(.*)$ index.php?/$1 [NC,L,QSA]
  #RewriteRule ^(.*)$ index.php/$1 [NC,L,QSA]

  #RewriteRule ^(.*)$ GameDev/index.php?/$1 [NC,L,QSA]
  RewriteRule ^(.*)$ GameDev/index.php/$1 [NC,L,QSA]

If that doesn't work, then try:
Code:
#RewriteRule ^(.*)$ index.php?/$1 [NC,L,QSA]
  #RewriteRule ^(.*)$ index.php/$1 [NC,L,QSA]

  RewriteRule ^(.*)$ GameDev/index.php?/$1 [NC,L,QSA]
  #RewriteRule ^(.*)$ GameDev/index.php/$1 [NC,L,QSA]



Can't remove index.php from the URL - El Forum - 05-26-2009

[eluser]Dam1an[/eluser]
Instead of specifying the name of the sub directory, can you not just use a dot to specify the current directory? Thats what I use (based on Dans suggestions a year ago) and it works

Code:
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico|license.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]



Can't remove index.php from the URL - El Forum - 05-26-2009

[eluser]chotz[/eluser]
Dan

I actually have the code igniter "system" folder in htdocs(web root)folder.

but my controller classes are in /system/application/controller/GameDev/
and similarly models and view classes.
So do i have to use : RewriteRule ^(.*)$ index.php?/$1 [NC,L,QSA]
or
#RewriteRule ^(.*)$ CI_Application/index.php?/$1 [NC,L,QSA]

Also do i have to place these lines in my .htaccess file?
(i assumed that these are for unix/linux)

Options -Indexes
Options +FollowSymLinks
Options -MultiViews
DirectoryIndex index.php


Can't remove index.php from the URL - El Forum - 05-26-2009

[eluser]DimCI[/eluser]
I guess the 3 lines in your .htaccess (the 1-st post) should work (because I use literally the same Wink

I'd ask server admins whether they have blocked any .htaccess-related capabilities in their .conf files may be..


Can't remove index.php from the URL - El Forum - 05-26-2009

[eluser]skunkbad[/eluser]
Does any URL rewriting work on your server? If you try other tests, and they don't work either, then at least you wouldn't drive yourself crazy thinking it was CI related.

For reference, here is my .htaccess:

Code:
# Turn on URL rewriting
RewriteEngine On

# Installation directory
RewriteBase /

# Rewrite all non-www URLs to www, except requests for pages from shared SSL
RewriteCond %{HTTP_HOST} !^www\.mysite\.com$ [NC]
RewriteCond %{HTTP_HOST} !^secure.mysite.com$ [NC]
RewriteRule ^(.*)$ http://www.mysite.com/$1 [L,R=301]

# Protect system directory from being viewed directly
RewriteRule ^(system) - [F,L]

# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Even though this file doesn't exist, skip it so it can be redirected
RewriteCond %{REQUEST_FILENAME} !^current-projects.php [NC]

# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT,L]

redirect 301 /current-projects.php http://www.mysite.com/development.php

<Files *.ini>
order deny,allow
deny from all
allow from mysite.com
</Files>

Options -Indexes

SetEnv PHPRC /home/dirbase/public_html/php.ini



Can't remove index.php from the URL - El Forum - 05-26-2009

[eluser]Colin Williams[/eluser]
Is your .htaccess file even being invoked? If the AllowOverride directive is set to "None" then .htaccess is ignored.


Can't remove index.php from the URL - El Forum - 05-26-2009

[eluser]Daniel Moore[/eluser]
@Dam1an: Yes, a dot can be used to specify the current directory, but that does not appear to be his problem at this point.

@DimCI: Chotz has stated he is running on his local Windows machine. Server admins would not be applicable.

@chotz: You have in your .htaccess file:
Code:
RewriteBase /GameDev/

Which is why I assumed you needed
Code:
RewriteRule ^(.*)$ GameDev/index.php/$1 [NC,L,QSA]

However, you have since stated:
[quote author="chotz" date="1243367961"]Dan
I actually have the code igniter "system" folder in htdocs(web root)folder.

but my controller classes are in /system/application/controller/GameDev/
[/quote]

This means you have set your RewriteBase WRONG. If your index.php is in your htdocs directory, that is, your web root. You SHOULD have the following:
Code:
RewriteBase /

That would mess you up fairly quickly.

If this does not fix your problem, then I need you to provide the following:

1. Since you have stated you are running on Windows, and have an htdocs directory, please verify that you are running XAMPP, and what version. If not XAMPP, then what server software are you running.

2. Give a breakdown of the directory structure you are using, starting with your DocumentRoot defined in apache.

For example:
--htdocs
------index.php
------system
----------application

If this example IS your setup, then please confirm that.

3. Give the values of the following from your system/application/config/config.php file:
$config['base_url']
$config['index_page']
$config['uri_protocol']