Chief Technology Officer & Photographer | Irvine, CA

Remove index.php from Codeigniter URL’s

I’m sure this already exists out on the net, but I found a little gem today.  When you are working with Codeigniter, you can remove the index.php from your URL’s by creating an .htaccess file with the following information:

RewriteCond $1 !^(index\.php|sitemap\.xml|robots\.txt|user_guide|blog|public|favicon\.ico|LiveSearchSiteAuth\.xml)
RewriteRule ^(.*)$ /index.php/$1 [L]

If you notice, I have some other stuff in there to not exclude from passing to index.php like a sitemap.xml, the user_guide directory, the blog directory, a “public” directory (that I use for css/images/js), etc.

You set that in your .htaccess file first, then go into your config.php file and set this:

$config['index_page'] = "";

Basically, what that does, is that removes the whole site from processing through index.php in the URL bar (it still goes through there as far as I know, but doesn’t show it), specifically when using Codeigniter built-in functions like redirect().

Figured I’d share that little nugget of knowledge…happy coding!

Speak Your Mind