This tutorial shows how to remove index.php from URL in Codeigniter. We want to remove the index.php file so that URL looks good and it makes better readability. Also the clean URL is easy to remember.

Before you change anything in comfig.php and .htaccess file make sure you have mod_write enabled in the server ottherwise it won’t work. For localhost you can enable it yourself and for live server if it does not work then you can contact with the hosting company.

<root directory> – is the root directory under htdocs in localhost or public_html(live server)
Check below things in <root directory>/application/config/config.php file


$config['base_url'] = '';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
$config['url_suffix'] = '';


Put the below lines in .htaccess file which is under <root directory>


#Initialize mod_rewrite
RewriteEngine On
# Put your installation directory here:
# If your URL is, use /
# If your URL is, use /site_folder/
RewriteBase /<root directory>/
# Do not enable rewriting for files or directories that exist
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#For reuests that are not actual files or directories,
#Rewrite to index.php/URL
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index\.php [NC]
RewriteRule ^ /%1 [R=301,L]


That’s all. Thanks for your reading. Please do not forget to leave a comment.


I am a professional Web developer, Enterprise Application developer, Software Engineer and Blogger. Connect me on JEE Tutorials | TwitterFacebook Google PlusLinkedin | Reddit

2 thoughts on “How to remove index.php from URL in Codeigniter

  1. I needed to thank you for this great read!! I certainly loved every bit
    of it. I have you bookmarked to look at new stuff you post…

Leave a Reply

Your email address will not be published. Required fields are marked *