Online Snippets Library

Remove index.php from URL In Codeigniter

To remove index.php from URL in codeigniter, we create ".htaccess" and place it in root directory of codeigniter.

Htaccess File code

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

URL Before htacess file

http://localhost/CodeIgniterFolder/index.php/home

URL after htacess file

http://localhost/CodeIgniterFolder/home

Sample file structure given below.

  • localhost/CodeIgniterFolder
  • localhost/CodeIgniterFolder/application
  • localhost/CodeIgniterFolder/system
  • localhost/CodeIgniterFolder/.htaccess

Note:In mycase CodeIgniterFolder is main folder.


remove-index.php-from-url-in-codeigniter