How to remove index.php from URL with CodeIgniter?

Introduction

The following has been tested on a Cloud9 server with the following versions:

Based on the CodeIgniter tutorial

Configure .htaccess file

If your Apache server has mod_rewrite enabled, you can easily remove this file by using a .htaccess file with some simple rules. Here is an example of such a file, using the “negative” method in which everything is redirected except the specified items:

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

In the file /application/config/config.php update the variable $config['index_page'] in order to remove the index.php:

$config['index_page'] = '';

See also


Last update : 11/23/2021