How to remove index.php in CodeIgniter
Home » BLOG » Web development » How to remove index.php from URLs in CodeIgniter

How to remove index.php from URLs in CodeIgniter

category:  CodeIgniter, Web development
1 min read

By default, the index.php will be included in the URLs as it shows below.

“https://example.com/index.php/users/login”

You can remove the index.php by following the steps below.

Apache server

  • If you use the Apache server and have mod_rewrite enabled, you can remove the index.php by using a .htaccess file. Below is the code you will place into your .htaccess file. If you don’t have this file yet, you can create one.
RewriteEngine on
RewriteCond $1 !^(index\.php|assets|images|js|css|uploads|favicon.png)
RewriteCond %(REQUEST_FILENAME) !-f
RewriteCond %(REQUEST_FILENAME) !-d
RewriteRule ^(.*)$ ./index.php/$1 [L]
  • Next, open application/config/config.php and look for $config[‘index_page’] and remove index.php. Below is the code you will see after removing the index.php from $config array.
$config['index_page'] = '';

And that’s it. The index.php is removed from the URLs.

If you are new to CodeIgniter, you can read the CodeIgniter tutorial from here.