Remove index.php from url codeigniter

Rakesh Sharma      18 Comments  

How to remove index.php from url codeigniter :-

If we need a clean url in codeigniter. we need to remove index.php from url in codeigniter. Default you will get index.php in url in codeigniter cause index.php file included with url in codeigniter. so url looks like :-

codeigniter provide easy way for url rewrite functionality to get clean url or remove index.php from url in codeigniter. we can easily done by using .htaccess some of config file changes. after remove index.php from url you will see controller name in url like “”.
We need to remove index.php from url so we can get clean url for our codeigniter site and url not looks odd or to get a user friendly or seo friendly url.

Steps to remove index.php from url codeigniter :-

Config changes :- Go to “application/config/config.php”

Find below code:-

$config['index_page'] = 'index.php'; 

Replace with the below code:-

$config['index_page'] = '';

.htaccess changes :- If you not have any htaccess create new and place it on your root.

Note :- if you have codeigniter in subdirectory change RewriteBase / to RewriteBase /subdir/

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

Now open your site pages you will found clean url with no index.php. so your all url looks like Now any of HTTP request for index.php will be treated as a request for your index.php file.

If still issue:- Need to apply one more config changes.
Go to “application/config/config.php”
Find below code

$config['uri_protocol'] = 'AUTO'; 

Replace with the below code

$config['uri_protocol'] = 'REQUEST_URI';

Now you have fully done to remove index.php from url codeigniter and getting clean url in codeigniter.

  • Sagar Bajaj

    Internal Server Error

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

    Please contact the server administrator at to inform them of the time this error occurred, and the actions you performed just before this error.

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

    Apache/2.4.9 (Win64) PHP/5.5.12 Server at localhost Port 80

    • rakesh sharma

      How you enabled mod_rewrite on your server? else try to include index.php in url it works? then it’s reason of mod rewrite

  • kishorjyotisarma

    not working.. :(

    • rakesh sharma

      Have you found any error?

      • kishorjyotisarma

        its ok now . Working fine.. :)

  • Ken Siosan

    Thanks , it works :) installed my CodeIgniter in XAMPP .. . htdocs/ci/cms

  • KH SolveCode

    + Copy .htaccess from Application to Root folder

    + edit .htaccess and put

    RewriteEngine On

    RewriteBase /ci_test/

    #Removes access to the system folder by users.

    #Additionally this will allow you to create a System.php controller,

    #previously this would not have been possible.

    #’system’ can be replaced if you have renamed your system folder.

    RewriteCond %{REQUEST_URI} ^system.*

    RewriteRule ^(.*)$ /index.php?/$1 [L]

    #When your application folder isn’t in the system folder

    #This snippet prevents user access to the application folder

    #Submitted by: Fabdrol

    #Rename ‘application’ to your applications folder name.

    RewriteCond %{REQUEST_URI} ^application.*

    RewriteRule ^(.*)$ /index.php?/$1 [L]

    #Checks to see if the user is attempting to access a valid file,

    #such as an image or css document, if this isn’t true it sends the

    #request to index.php

    RewriteCond %{REQUEST_FILENAME} !-f

    RewriteCond %{REQUEST_FILENAME} !-d

    RewriteRule ^(.*)$ index.php?/$1 [L]

    # If we don’t have mod_rewrite installed, all 404’s

    # can be sent to index.php, and everything works as normal.

    # Submitted by: ElliotHaughin

    ErrorDocument 404 /index.php

    Note: make sure your web server is enable for “rewrite_module”

    + Remove index.php from $config[‘index_page’] = ‘index.php';

    – edit config.php in application/config

    – search for index.php

    change it from $config[‘index_page’] = ‘index.php'; to $config[‘index_page’] = ”;

    Please watch this videos for reference

  • raknjak

    worked perfectly CentOS and WAMP thanks!

  • webenlive

    not working :(. 404 error fount

    • 林揚曙


  • uzair ahmad

    working perfectly (y) thnx

  • Andy Ajhis Ramadhan

    i was try but page still not found. in CI 3.0

  • Alvian Casablanca

    I have followed your instructions. It does show difference. Initially, when I visit localhost/controller/method it tells no page found but after I did the procedure above and visit the same URL, it always redirects to localhost/xampp instead. What should I do? Much Thanks Rakesh Sharma.

  • Zeeshan Ali Khan

    For all those are working with apache, Check for AllowOverride directive in your apache2.conf file, it is None by default just change it to All and restart apache service. Then only the .htaccess file will be recognised by apache.

    • Chief Frank

      Thank you very much. I just signed in to upvote and say thanks to your answer!

      • Zeeshan Ali Khan

        You are welcome :)

  • Dhaval Dave
  • binil billu

    showing 404 error with CodeIgniter 3.1 apache linux server