How to remove index.php from URL in CodeIgniter

No votes yet.
Please wait...

Hello Guys,

Many of our fellow developers had spend hour’s in searching for the right solution to remove index.php from CodeIgniter (CI) URL’s like we did in our earlier stages of becoming an PHP professional.

Having index.php in your CI project is just like an unnecessary burden being carried out so let’s get rid of it without affecting our precious code.

For accomplishing the task a series of steps needs to be followed. Just follow these 3 simple steps and you’re done.

  • The first step is to go some settings in our config.php file located under config folder. Open the file and set
    • $config[‘index_page’] =’ ‘; 
    • $config[‘uri_protocol’] = ‘AUTO’;
  • The second step is to remove the index.php from your URL parameters located in constants.php file and Base URL (present in config.php file) and everywhere you have defined the URL.
  • The third and last step is to upload a .htacess file on root on the website containing following code.
1
2
3
4
5
6
7
8
9
10
<IfModule mod_rewrite.c>
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php?/$1 [L]

</IfModule>

 

Now just run your project and click on the navigation links the index.php disappears without affecting your website.

Download the .htaccess file

That’s all we have for this blog we will be back soon with some more interesting development hacks.

Cheers!

Because Hurdles aren’t really hurdles.

2 Comments

  1. Credo Systemz said:

    great blog.. after reading this blog i got more useful information which really helpful to cracking the php interview..

    No votes yet.
    Please wait...
    April 14, 2017
    Reply
    • Saurabh Dubey said:

      Thank You Mate

      No votes yet.
      Please wait...
      April 18, 2017
      Reply

Leave a Reply

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