In codeigniter by default, the index.php file will be included in every URLs, For example if you installed codeigniter locally like this “localhost/” or in a folder like this “localhost/codeigniter/”, if you want to go to any page, for ex: a page named demo, You should go to demo page like this “localhost/codeigniter/index.php/demo/”, otherwise you will get an error (“URL Not Found”).

You can easily remove this file by using a .htaccess file with some simple rules.

Copy this code and paste it into any text editor

 RewriteEngine On
 RewriteBase /{'<i>Your codeigniter folder name,if you installed codeigniter in a subfolder, Otherwise leave it with one backslash</i>'}/
 RewriteCond %{REQUEST_URI} ^system.*
 RewriteRule ^(.*)$ /index.php/$1 [L]
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule ^(.*)$ index.php/$1 [L]
view rawhtaccess hosted with ❤ by GitHub

and save the file with the name .htaccess, this file must be in your codeigniter root folder.

Now you can navigate your site’s structure without the index.php in front of every URL

Related Posts