CodeIgniter Remove Index php from URL

Everyone should want to remove trailing index php from URL after installing CodeIgniter. Removing Index.php from URL, it looks clean and more search engine friendly. That’s why you want too. You can remove index php part of the URL by adding a.htaccess” file to the root of your CodeIgniter install. 

Steps to Remove Index php from URL:

Step:-1 Open the directory “application/config” and open the file “config.php“. find and replace the below code in config.php file.

//find the below code

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

//replace with the below code
 
$config['index_page']=""

Step:-2 Go to your CodeIgniter directory and create .htaccess

Your_website_root_dir/
  |->application/
  |->assets/
  |->system/
  |->.htaccess <———Create this file 
  |->index.php

Step:-3 Write below code in .htaccess file

<IfModulemod_rewrite.c>

   RewriteEngine On
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteRule ^(.*)$ index.php/$1 [L]

</IfModule>

The above code checks requested file(-f) with the specified name in the browser exist, or the directory(-d) in the browser exist. If does not exists then proceed to the rewrite rule below.

Step:-4 In some case the default setting for uri_protocol does not work properly. To solve this problem just open the file “application/config/config.php“, then find and replace the below code.

 //find the below code 
$config['uri_protocol']="AUTO"

//replace with the below code 
$config['uri_protocol']="REQUEST_URI"

 This will work on all apache based web server but in wamp server, it does not work because rewrite_module by default disabled so we have need to enable it.

 

<<Previous                                                                                      Next>>

The following two tabs change content below.

Subroto Mondal

Chief Coordinator HR&CR
I like Programming and New Technologies. And work with Linux.

3 thoughts on “CodeIgniter Remove Index php from URL

  1. Pingback: CodeIgniter Base URL Configuration - NHIT Tech Blog

  2. Pingback: CodeIgniter Route Configuration - NHIT Tech Blog

  3. Very nice post. I just stumbled upon your weblog and wanted to say that I’ve truly enjoyed browsing your weblog posts.
    After all I will be subscribing for your rss feed and I hope you write once more soon!

Leave a Reply

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

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