Friday 11 September 2015

How To Remove index.php From URL in Codeigniter

Once we install the default Codeigniter 3.0 then by default there is index.php in the URL. So the URL looks like http://www.yourdomain.com/index.php/controller/function
For SEO point of view we require a clean URL and codeigniter provide easy way to remove index.php for URL rewrite functionality. It can be easily achieve by using .htaccess and few changes in config file.
Follow the steps to remove index.php from URL:

Step 1: Go to “application/config/config.php”
Find below code:-
$config['index_page'] = 'index.php';
$config['index_page'] = '';

Step 2: create htaccess file on your project root location and add following lines : PHP
RewriteEngine on
RewriteBase /
RewriteCond $1 !^(index.php|resources|robots.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

After that your website URL has been cleaned and new URL will be http://www.yourdomain.com/ controller/function

No comments:

Post a Comment