If you are using Codeigniter you are noticed that by default index.php will be included with your URL. We should remove it 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 from URL in Codeigniter

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

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]

Removing 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

Related Posts