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.

6 Comments

  • 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!

  • Very good info. Lucky me I ran across your blog
    by accident (stumbleupon). I have book-marked it for later!

  • If you want to increase your know-how only keep visiting this site and be
    updated with the most recent news update posted here.

  • Thank you for some other informative blog. The place else may just
    I get that type of information written in such an ideal method?
    I’ve a project that I am just now working
    on, and I’ve been on the look out for such information.

  • What’s up to every body, it’s my first go to see of this weblog;
    this website contains awesome and really excellent data in favor
    of readers.

  • It’s amazing to visit this website and reading the views of
    all mates about this piece of writing, while I am also eager of getting
    know-how.

2 Pingbacks

Leave a Comment

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.