Last updated on January 17, 2018
I would like to explain about removing index.php from codeigniter based application urls with .htaccess.To hide “index.php” from the URL, add an .htaccess file to your web root, with following text:
RewriteEngine On RewriteBase / #request to index.php RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?/$1 [L]
NOTE: If you are website located in sub directory , instead of ‘RewriteBase /
‘ add ‘RewriteBase /sub directory name
‘.For example if you webiste located in htdocs/ciapp/ then the rule should be RewriteBase /ciapp
.
After add .htaccess file go to applications/config/ open config.php, in the config array, remove index_page value
$config['index_page'] = “index.php”; //to $config['index_page'] = “”;
In some cases default settings of uri_protocol doesn’t work properly.To fix this problem just change below code in config.php located at application/config/ directory
$config['uri_protocol'] = “AUTO” //with $config['uri_protocol'] = “REQUEST_URI”;