How toremove index.php from Codeigniter URL ?

If you are using Codeigniter you are noticed that by default index.php will be included with your URL. We should remove index php codeigniter because its very ugly to have it in all the urls. So lets see how to  remove index.php  from url in Codeigniter from  Apache and Nginx  Servers separately

remove index php codeigniter

I will tell you how to remove index.php from url from codeigniter in apache and nginx server.

Contents

Htaccess Code to Remove index.php from URL from Codeigniter in Apache Server

Create a “.htaccess”file in the root of CodeIgniter directory (where the system directory resides), open the file using your favorite text editor, write down the following script 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]

Remove index php from URL from Codeigniter in Apache Server (Sub Directory)

If your codeigniter application is located in subdirectory then please include this line  RewriteBase /subdirectory/ 

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

Code to Remove index php from url from Codeigniter in Nginx Server

If your Codeigniter application is on Nginx server, then please include the below in your nginx.conf file under server block

location / {
try_files $uri $uri/ /index.php?$args;
}

 

Once you updated the changes in your server then you can access the urls without index.php

Before updating the code, your url looks like

 http://ci.w3lessons.info/index.php/memcached 

 

After you made the changes, your url looks like

 http://ci.w3lessons.info/memcached 

 

Please check my codeigniter posts and tutorials

Please subscribe to my blog to get latest updates via email.

Thanks

You May Also Like

Never Miss Any Web Tutorials, Guides, Tips and Free eBooks

Join Our Community Of 50,000+ Web Lovers and get a weekly newsletter in your inbox

 

I hate spam too. Unsubscribe at any time.

4 thoughts on “How toremove index.php from Codeigniter URL ?”

Leave a Comment