Codeigniter remove index.php from url


When we are working with codeigniter you can see index.php in the url after the base_url.So here we’re discuss how to remove index.php part from the url.We can do it using htaccess file and config file.

Here is the example.

We want to remove index.php part from this url as follows.

remove index.php from url using htaccess and config file?

1-Go to the /application/config directory and open the config.php file.

2-Put the “index.php” variable as empty.

3-Put the “uri_protocol” as “REQUEST_URI”.

4-Go to the root codeIgniter directory(same location of “system” folder) and open the htaccess file. If not exist create a new one.
Codeigniter remove index.php from url

Copy the following code and paste and save it.

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

If not success, put this code instead of the above code.

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

Note: If you call with index.php part, no problems, it is also work!
If you got “Internal server Error!” Please double check your .htaccess file and config.php file.
That’s only.


About Author

Sumith Harshan is the Web Engineer Specializes in Java Script, JQuery, HTML4/5, CSS2/3, PHP, CodeIgniter, CakePHP, J2SE, J2EE, XML, Hacking & Security, Mobile Interface Developing, Magento, Wordpress, Joomla, Drupal,PHPBB,Facebook App Developing and Open cart...etc.

  • anshul gupta

    9c tuts

  • Joe

    in xampp index.php is removed by having .htaccess, But for IIS server it s not working,
    Can u give solution to remove index.php in codeigniter for IIS server

    • Please check the complete web.config file. Place this in the same folder where the index.php is placed.