Search code examples
linuxapache.htaccesscodeignitermod-rewrite

Codeigniter URL rewriting .htaccess is not working on CentOS


I've created a .htaccess file in my document root at /var/www/html/ to rewrite URL of Codeigniter to remove "index.php" from URL of all pages.

e.g. Change URL from

http://myhost/index.php/controller/function

to

http://myhost/controller/function`

Here is the code of my `/var/www/html/.htaccess

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

I've got many suggestions from googling to enable mod-rewrite module, but I can see in my httpd.conf its already enabled.

LoadModule rewrite_module modules/mod_rewrite.so

This is perfectly working on my local system running on Debian 7 (Apache/2.4.4).

Any help would be appreciated. :)


Solution

  • You need to also specify the locations that can use it. For example, in /etc/httpd/conf/httpd.conf you should see something like:

    <Directory "/var/www/html">
    
          ...lots of text...
    
    </Directory>
    

    Make sure is has:

    <Directory "/var/www/html">
    
        AllowOverride All
    
    </Directory>