Showing posts with label Codeigniter. Show all posts
Showing posts with label Codeigniter. Show all posts

Sunday, June 24, 2012

How to remove index.php from Codeigniter URL

In codeignetor, your apps url include with index.php by default. Like as : 
http://naimrajib.blogspot.com/index.php/[controller-class]/[controller-method]/
But you can easily remove index.php from your CodeIgniter’s URL so that your URL should be like:
http://naimrajib.blogspot.com/[controller-class]/[controller-method]/

To do this just follows the following steps:
  1. Open config.php from system/application/config directory and replace
    $config['index_page'] = “index.php” by   $config['index_page'] = “”

  2. Create a “.htaccess” file in the root of CodeIgniter directory (where the system directory resides).

  3. open the ".htaccess" file using your favorite text editor, write down the following script and save it:
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA] 

  1. In some case the default setting for uri_protocol does not work properly.
To solve this problem just replace
$config['uri_protocol'] = “AUTO” by
$config['uri_protocol'] = “REQUEST_URI”

from system/application/config/config.php