Common .htaccess for clean URI’s in CI

I remember when I started with CI back in the day that I always had a issue trying to get mod_rewrite to work so I could work with clean URLs in CI. Well it’s really not all that hard but I decided I will give you a very common .htaccess that should work on most web hosts. I will say that Godaddy is very abnormal in their structure so I’ve provided a alterative example for Godaddy.

First lets change a few things within your CI configs to make it work.
Open up config.php in application/config/config.php and edit this line:
‘$config['index_page'] = ‘index.php’;’ and replace it ‘index.php’ with a blank quotes ”.

Next depending on your server’s setup you may need to update this line:
‘$config['uri_protocol'] = ‘AUTO’;’
and change AUTO to QUERY_STRING or REQUEST_URI depending on your server setup. For example Godaddy uses QUERY_STRING.

Now in the root of your application create a file called ‘.htaccess’ and place the following code into it, if using Godaddy then choose the second example.

Common .htaccess

RewriteEngine On
RewriteCond $1 !^(index\.php|static)
RewriteRule ^(.*)$ index.php/$1 [L]

In this example you will want to include any folders/directories and files that you need accessible, separated by pipes ‘|’.

Godaddy (Query String) .htaccess

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?$1 [L]


Give this a go, I hope it will help you out with any issues you might come across trying to implement this.