Remove index.php from your Codeigniter application URL
If you are using Codeigniter for developing PHP applications you noticed the “index.php” part of the URL of your application.
You can remove it by doing two simple things:
1. Edit the config.php from .system/application/config/ and change the $config['index_page'] like this: $config['index_page'] = “”;
2. Create a .htaccess page in the root of the Codeigniter application:
RewriteEngine On
RewriteBase /CIapplication
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Edit line two in order to suit your setup.
Now you will be able to use: http://server.com/CIapplication/controller instead of: http://server.com/CIapplication/index.php/controller
In case this is not working, modify this line in config.php:
$config['uri_protocol'] = "AUTO";
and change it to:
$config['uri_protocol'] = "REQUEST_URI";
You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.





November 3rd, 2008 at 4:27 pm
thanks for this information!
December 26th, 2008 at 4:27 pm
thanks for your information
December 29th, 2008 at 4:04 am
This is just what i needed!
December 29th, 2008 at 2:47 pm
Hy… This is not working for me. I have modified the config.php file and it`s still not working.
December 29th, 2008 at 9:29 pm
I would try to help you, but please provide more information
Do you get any error? Do you get the 404 File not found from web server, or the File not found error from CI?
December 30th, 2008 at 3:56 pm
So… I succeed in making it to work for a website… It was from my Apache configuration. But when I tried to do the same for another website it`s not working again. I get the 404 error. Not Found. The .htaccess file is created and changed for this website, the server configurations are the same, when I access http://localhost/site_name/ it works but when I access http://localhost/site_name/welcome/ it isn`t work. It is working only if I access http://localhost/site_name/index.php/welcome/
December 30th, 2008 at 3:58 pm
As I see I`m the only one that has problems with this so I think that there is something that I`m not doing right. But I can`t understand what.
December 30th, 2008 at 4:06 pm
Try to change in httpd.conf:
Options All
AllowOverride All
and see if it works. Also check if apache has mod_rewrite on
December 30th, 2008 at 4:21 pm
Well I most say that I`m a little bit confused about this httpd.conf file when we start to talk about AllowOverride All.
So it works now but what have I done? I had deleted the
AllowOverride All
and istead of old_website I put the new_website… It seems to work for new_webstie. I`ve done this to see if it works but if I put two one with old_website and one with new_website… It seems to work only for the first that is in the httpd.conf.
Apache has mod_rewrite on because I activated it when I started to work with this. I have changed in Options All AllowOverride All but it works in the same way, only the first.
December 30th, 2008 at 4:24 pm
OK, now it`s done, I`ve modified again the httpd.conf file and it seems to work very good. Thanks again and I`m sorry for the inconvenience.
December 30th, 2008 at 6:02 pm
AllowOverride All tells Apache to use the “settings” in .htaccess, if any.
More here:
http://httpd.apache.org/docs/2.0/mod/core.html#allowoverride
Anyway, i’m glad it works after all
)
If you have any more questions, you can find me on yahoo messenger, id: pc_tips
It seems we use the same time zone
April 15th, 2009 at 12:27 am
I recently came across your blog and have been reading along. I thought I would leave my first comment. I don’t know what to say except that I have enjoyed reading. Nice blog. I will keep visiting this blog very often.
John Marker
June 25th, 2009 at 8:03 pm
Thanks mate.
August 3rd, 2009 at 11:42 am
Well done dude! Thanks so much
Richie
August 28th, 2009 at 8:41 am
Thanks for post and providing detailed information about to make changes in .htaccess and make it workable. But my question to you is, whether this provided solution is applicable to the websites those are hosted on Shared Hosting?
Nitin
August 28th, 2009 at 8:53 am
Hello Nitin
I used this on Hostgator, GoDaddy and Bizland.
On Bizland, the line:
RewriteRule ^(.*)$ index.php/$1 [L]
should be changed to
RewriteRule ^(.*)$ index.php?$1 [L]
Regards
September 3rd, 2009 at 3:18 pm
Thanks for the guide on how to do it on hostgator. I’m using it and was wondering how to do it and whether it may work or not. You cleared my daubt.
September 27th, 2009 at 10:31 am
[...] : PC TIPS.NET, CI User Guide. Categories : CodeIgniter, php Tags : php, tutorial codeigniter, [...]
October 11th, 2009 at 5:09 pm
Excellent tips on how we doit on server side removal. Thank you for your sharing on removing index.php name in URL. I always hate to see that index.php at the suffix of each main URL.
November 22nd, 2009 at 2:29 pm
hi man,
I deploy in XAMPP server. It doesn’t work.
Thanks,
Jack
November 22nd, 2009 at 3:24 pm
Can you be a little more specific? Did you try to change $config['uri_protocol'] in config.php?
December 1st, 2009 at 7:47 pm
hi jack
For xamp i have created a .htaccess with these lines
—————————————-
RewriteEngine On
RewriteBase /myapp
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#’system’ can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn’t true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
# If we don’t have mod_rewrite installed, all 404′s
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
——————————
and the parameter $config['uri_protocol'] = ‘AUTO’
It’s working fine for me
Thanks
December 1st, 2009 at 7:50 pm
RewriteEngine On
RewriteBase /myapp
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
January 3rd, 2010 at 6:35 am
Thanks for your tips
March 1st, 2010 at 8:38 am
i’m using zend server CE.
it’s not working!
what i shoud do to be working?
please help!
March 11th, 2010 at 3:28 am
Sorry but I never used it.
April 8th, 2010 at 3:38 am
I tried the example in the tutorial i did exactly as is there but i was given the following errors
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, admin@localhost.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.
Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.
April 9th, 2010 at 11:02 pm
Can you tell me what’s in error_log? You may not have mod_rewrite loaded
June 4th, 2010 at 3:15 pm
This is not working. I do every thing u mention but it still create problem.
June 7th, 2010 at 1:38 pm
.htaccess file
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
ErrorDocument 404 /index.php
I place It In Test/
And Test Contain Test/System and index.php
It gives Server Internal Error
June 18th, 2010 at 12:02 am
first of all you should have
RewriteBase /Test
June 21st, 2010 at 1:40 pm
I have moved my site on remote & I have installed Code Igniter in root directory.what i should write in .htaccess
RewriteBase / OR
RewriteBase http://www.mysite.com
June 30th, 2010 at 3:29 am
Should be
RewriteBase /
July 5th, 2010 at 9:43 am
Thanks man it helped