How to remove index.php file from URL in Codeigniter

Hello, This is my first post after the Hello World Post. Today I am going to teach you how to remove index.php file from URL in Codeignitor.   When you redirect to your view in Codeignitor, you have to insert index.php file also. Show the below Example,

http://www.yourServer.com/index.php/controller/function

This is a headache to me.  So I wanted to remove Index.php file from URL and make my site URL beautiful. Like This,

http://example.com/controller/function


OK. Let's do it Step by step.



Step 1

Go to the Config file in application/config/ directory and find the following code.

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


Then, you have to replace this line with below code.

$config['index_page'] = '';


After that save the File and close the File.


Step 2

I hope that you have done the Step 1 above in this blog post. OK, Let's do the second  step.
You have to create .htaccess file in CodeIgnitor folder (Not in Application Folder)

See Below Image.

Then, Open the .htaccess file and Copy and Paste following code snippet inside your .htaccess file. Save it... !

<IfModule mod_rewrite.c>

    RewriteEngine on

    RewriteCond %{REQUEST_FILENAME} !-f

    RewriteCond %{REQUEST_FILENAME} !-d

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

</IfModule>



Step 3

You are almost done. One more step to go. go to the "application/config" directory again and find the following code snippet.

$config['uri_protocol'] = 'AUTO';


Replace above line with following code snippet.

$config['uri_protocol'] = 'REQUEST_URI';



That's All !!!!

Now you Can Remove index.php file from url and make your site URLs Handy !!!!


0 comments:

Post a Comment

Ask anything about this Tutorial.