December 08, 2013

December 08, 2013
3
In this article, we are going to discuss about How to enable SEF url in CodeIgniter (CI). We can get the SEF url by removing the index.php from the URL. If you are using Codeigniter you are noticed that by default index.php will be included with your URL. In this article I am going to explain about How to remove the index.php from the CodeIgniter (CI) site URL.

By removing the index.php from the URL we can get the site URL like below

http://domain.com/about

To acheive this, follow the below steps.

Step 1 :

Open the folder "system/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 :

Create ".htaccess" file in the root of CodeIgniter (CI) directory. Then the below codes in the ".htaccess" file.

RewriteEngine on
RewriteCond $1 !^(index.php|resources|robots.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

In some case the default setting for uri_protocol does not work properly. To solve this problem just open the file "system/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" 

3 comments: