How to remove "index.php" in codeigniter's path
Solution 1
If you are using Apache place a .htaccess file in your root web directory containing the following:
RewriteEngine on
RewriteCond $1 !^(index\.php|[Javascript / CSS / Image root Folder name(s)]|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
Another good version is located here:
http://snipplr.com/view/5966/codeigniter-htaccess/
Solution 2
I had some big issues with removing the index.php. As a general rule the .htaccess below has been tested on several servers and generally works:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
<Files "index.php">
AcceptPathInfo On
</Files>
If you don't have any luck with that then the next step is to adjust your config file. Try some of the other URI protocols e.g.
| 'AUTO' Default - auto detects
| 'PATH_INFO' Uses the PATH_INFO
| 'QUERY_STRING' Uses the QUERY_STRING
| 'REQUEST_URI' Uses the REQUEST_URI
| 'ORIG_PATH_INFO' Uses the ORIG_PATH_INFO
$config['uri_protocol'] = 'ORIG_PATH_INFO';
If your still not having any luck try changing the rewrite rule to include your subfolder. This is often a problem if your using a temporary URL on a dev server etc:
RewriteRule ^(.*)$ /subofolder1/subfolder2/index.php/$1 [L]
Just play around with these options, one should work. Also, make sure your index file is set to:
$config['index_page'] = '';
Good luck!
Solution 3
Have the.htaccess file in the application root directory, along with the index.php file. (Check if the htaccess extension is correct , Bz htaccess.txt did not work for me.)
And Add the following rules to .htaccess file,
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Then find the following line in your application/config/config.php file
$config['index_page'] = 'index.php';
Set the variable empty as below.
$config['index_page'] = '';
That's it, it worked for me.
If it doesn't work further try to replace following variable with these parameters ('AUTO', 'PATH_INFO', 'QUERY_STRING', 'REQUEST_URI', and 'ORIG_PATH_INFO') one by one
$config['uri_protocol'] = 'AUTO';
Solution 4
Have a look in the system\application\config\config.php
file, there is a variable named index_page
It should look like this
$config['index_page'] = "index.php";
change it to
$config['index_page'] = "";
Then as mentioned you also need to add a rewrite rule to the .htaccess
file
Note: in CodeIgniter v2 this file was moved out of the system folder to application\config\config.php
Solution 5
All above methods failed for me and then I found that I was not changing AllowOverride None to AllowOverride All in my virtual host file at /etc/apache2/sites-available/default
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride All <---- replace None with All
</Directory>
<Directory /var/www >
Options Indexes FollowSymLinks MultiViews
AllowOverride All <--- replace None with All
Order allow,deny
allow from all
</Directory>
...
Related videos on Youtube
OrangeRind
What about me? Nothing really. Regular guy. Bit of brain. Lots of interests.
Updated on July 08, 2022Comments
-
OrangeRind almost 2 years
How do I remove the
"index.php"
sticking out in every path in codeigniter somewhere in the center? I want clean nonindex.php-fied URLs
?-
Eldho NewAge about 6 years
-
-
OrangeRind over 14 years+1 for the link! Although had to tweak around a bit. got it with this --> RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [QSA,L]
-
Willy almost 12 yearsThank you so much, i got that AllowOverride None too, now it works !
-
Kevin Beal over 11 yearsThe blog is gone now, and I would very much have liked to read it. None of these solutions are working for me...
-
Ahmed Samy over 11 yearsthank you , i have been failing in this for long time dunno why but ur way worked like butter :D
-
mohsin.mr over 11 yearsAfter spending couple of hours, I read this and found my mistake.
-
sanji about 11 yearsThanks MDeSilva. This post save my time.
-
Jasdeep Khalsa almost 11 yearsAnother module I needed to enable was
actions
: stackoverflow.com/questions/14419757/… -
jsky almost 11 yearsi thought your first code here was the solution for me but actually it is just sending any url like domain/* to domain/index.php it ism't sending domain/welcome to the welcome controller. was excited for a second then. trying the other suggestions now.
-
Henry over 10 yearsfor some reason, i had to add a slash to the beginning of the RewriteCond.
RewriteCond $1 !^\/(index\.php|assets|robots\.txt)
-
Stony over 10 yearsThanks. It's works. BTW, I needn't change config.php.
-
CMCDragonkai over 10 yearsFor some reason, if you have index.php in the URL, it's not actually removed, it stays there and keeps working.
-
T.Coutlakis over 10 yearsThanks, this one helped me, I used PATH_INFO with WAMP
-
vadim over 10 yearsI also spent at least an hour because of this "little" trick. By default, the .htaccess files comes in
application
directory instead of root. -
JChow almost 10 yearsawesome, saved my day.
-
Roshdy over 9 yearsI used all the possible combinations and it's still not working for me!!!!! how did you get it to work??
-
Sean Vieira over 9 yearsYour Apache install needs to be configured to check .htaccess files - make sure that is the case.
-
Someone about 9 yearsTried using the first of the above examples works only on my root but not on form loads etc will still try to use index.php in urls I will play around and come back to this if I can firugre it out
-
Benjamin W. about 8 yearsWhile this code may answer the question, providing additional context regarding why and/or how this code answers the question improves its long-term value.
-
Dewald Els over 7 yearsThis is correct and straight from the CodeIgniter docs. I also using this method.
-
gomesh munda over 7 yearsThanks @Vinod.I was going crazy with this problem.I have been searching on the net for so long, tried various solutions but they never worked until i came across your solution.Now my CI project is working and it has given me NEW HOPE to move on with CI.Thanks a lot :)