Removing index.php from URLs in CodeIgniter

in CodeIgniter, Framework / 2 Comments

Hi friends, in this post I am going to explain how to removing index.php from URLs in CodeIgniter framework. In earlier we have learned few topics regarding CodeIgniter i.e. Pagination, Upload images and Database connection. Now we will learn how to remove index.php from URLs.

Removing index.php from URLs in CodeIgniter by Anil Kumar Panigrahi

Removing index.php from URLs in CodeIgniter by Anil Kumar Panigrahi

.htaccess file in root directory

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

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

In the application folder

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond $1 !^(index\.php|images|robots\.txt)
    RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>

In application/config/config.php

search for

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

and replace it with

$config['index_page'] = '';

Now we will get URLs without index.php

I am writing this code based on CodeIgniter 2.2.1

With more than 9 years experience in PHP and Founder of Anil Labs, a blog for PHP and related posts. contributed posts regarding CodeIgniter, CakePHP and Learn PHP online ...Contact : [email protected]

Discussion 2 Comments

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>