Jul 23 2008

Code Igniter mod_rewrite on Heart Internet

Published by admin at 9:07 pm under Code Igniter

I’ve used mod_rewrite quite a lot with Code Igniter and I’ve experienced issues getting it working to remove the index.php from the url on different servers before but this was another issue again. Here’s my resolution and some of my previous resolutions:

Here’s the contents of the .htaccess for Heart Internet to remove index.php:

RewriteEngine On
RewriteCond $1 !^(index\.php|css|img|js|robots\.txt) [NC]
RewriteRule ^(.+)$ index.php?/$1 [L]

SetEnv DEFAULT_PHP_VERSION 5

The SetEnv DEFAULT_PHP_VERSION 5 tells Heart to use PHP 5.

If you have any directories or specific files (like robots.txt) you need to access for css, JavaScript etc, they will need to be put them in the RewriteCond separated by a pipe (|).

In addition, I prefer working with short open tags for writing PHP. You need a file called php5.ini containing:

short_open_tag = On

For my XAMPP development I use the following code in my .htaccess:

RewriteEngine on
RewriteCond $1 !^(index\.php|css|img|js) [NC]
RewriteRule ^(.*)$ /index.php/$1 [L]

For other servers I’ve needed the following:

Options +FollowSymLinks
RewriteEngine on
RewriteCond $1 !^(index\.php|css|img|js|robots\.txt) [NC]
RewriteRule ^(.*)$ index.php/$1 [L]

The subtle differences (that make a huge difference between it working and not working) that may have not been noticed are all located around /index.php?/$1.

I hope this of some use.

Trackback URI | Comments RSS

Leave a Reply