Search code examples
php.htaccesscodeigniter

Codeigniter htaccess not working


I am using this htaccess file on my site to remove index.php.

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

But this file doesn't work.Rewriting is enabled in Apache module.Version of codeigniter used is 2.0.1.


Solution

  • I've tested this without codeigniter, and it works.

    I create a folder under htdocs, called "demo". I put ".htaccess" there with your content + additional line (RewriteBase):

    RewriteEngine on
    RewriteBase /demo/
    # RewriteCond $1 !^(index\.php)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L,QSA]
    

    Then "index.php" below:

    <?php
    echo $_SERVER['PATH_INFO'];
    

    Tested with: http://localhost/demo/hello

    Result: /hello


    Things to check:

    • If you put ".htaccess" inside a folder, don't forget to add RewriteBase.
    • Make sure FollowSymLinks is enabled for your directory. See this link for further information.