Menu

In this tutorial I will show you how to remove index.php in Codeigniter 3. The purpose remove index.php is help improve website SEO and make URL user friendly.

Example:

mysite/profile/john

instead

mysite/index.php/profile/john

by default, the index.php file will be included in your URLs.

If your Apache server has mod_rewrite enable (How to enable mod_rewrite module in Apache in XAMPP ),  you can easily remove this by using .htaccess file with some rules.

 

Step 1:

Open application/config/config.php file. At line 38, $config['index_page'] = 'index.php';

set it blank see example below:

$config['index_page'] = '';

and save it.

 

Step 2:

Create .htaccess file in root of codeigniter.

Step 3:

Write or just copy & paste to .htaccess file and save it.

Reference:  https://www.codeigniter.com/userguide3/general/urls.html

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

 

Step 4:

Now go to your browser to make sure it is work properly. Enter this URL without index.php :

localhost/mysite/welcome

Done. Congrats!

If you have problem regrading this topic, just comment below and I will try help you.