Rewriterule for CodeIgniter not working
Assuming that your configuration (/application/config/config.php) has the index_page disabled:
$config['index_page'] = '';
And your Apache DocumentRoot is: /srv/www/
Create an .htaccess file at the same level as your /application/ directory, with the following content:
<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?/$1 [L]</IfModule>
You should notice that RewriteBase points to the DocumentRoot (/).If the index.php is in another directory, your should change RewriteBase accordingly.
For a directory structure like:
/srv/www/application//srv/www/system//srv/www/index.php/srv/www/.htaccess
Your RewriteBase should be: /
For a directory structure like:
/srv/www/codeigniter/application//srv/www/codeigniter/system//srv/www/codeigniter/index.php/srv/www/codeigniter/.htaccess
Your RewriteBase should be: /codeigniter/
And so on, you get the picture.
I found the solution. The htaccess file wasn't allowed to run by the Apache config. So I had to set the AllowOverride
flag on the directory to AllowOverride ALL
.
Thanks for all the help!
Default .htaccess (from ci userguide http://ellislab.com/codeigniter/user-guide/general/urls.html)
RewriteEngine on RewriteCond $1 !^(index\.php|images|robots\.txt)RewriteRule ^(.*)$ /index.php/$1 [L]
I have confuse above code for a moment, but i have code like this:
RewriteEngine onRewriteCond $1 !^(index\.php|robots\.txt|.*\.css|.*\.js|.*\.png)RewriteRule ^(.*)$ ./index.php/$1 [L]
On localhost you must add "./" in front of index.php (3rd line) because in my case, ci directory not placed on root. I think "./" means it should be relative path.For additional condition ".*\.css|.*\.js|.*\.png"
, it means apache should not rewrite on file with extensions css, js and png.