how to remove index.php from codeigniter application url

In codeigniter applications we can see index.php in the url after the base_url. Below are steps how to remove index.php part from the url. We can do it by modifying .htaccess file and configuration file.

Here is a example.
Default url : http://www.mysite.com/index.php/contact-us

We want to remove index.php part from this url as follows.
After removal of index.php : http://www.mysite.com/contact-us

steps for removing 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.

$config[‘index_page’] = “”; // default value is “index.php”
3-Put the “uri_protocol” as “REQUEST_URI”.

$config[‘uri_protocol’] = “REQUEST_URI” // default value is “AUTO

4-Go to the root codeigniter root directory and open the .htaccess file. If not exist create a new one.

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, then also it will work

If you got “500 Internal server Error!”
double check your .htaccess file and config.php file for any mistake.

Comments
2 Responses to “how to remove index.php from codeigniter application url”
  1. Arun kumar says:

    i did the things which mentioned above and also double checked the .htaccess and config file.
    it showing “500 Internal Server Error ” – ” Internal Server Error

    The server encountered an internal error or misconfiguration and was unable to complete your request.

    Please contact the server administrator, admin@localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error.

    More information about this error may be available in the server error log. “

    • bput4all says:

      Hi there did you able to resolve the issue.i was quite busy so saw your mail now.
      Let me know if you still have the issue.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.