Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save masudcsesust04/d7fa9db3a3adb0b8198e292b2d7f46ac to your computer and use it in GitHub Desktop.
Save masudcsesust04/d7fa9db3a3adb0b8198e292b2d7f46ac to your computer and use it in GitHub Desktop.
Steps to remove index.php from the URL of a CodeIgniter application

1. First enable Apache rewrite module on by the following command.

sudo a2enmod rewrite

Then restart the apache service using command below.

sudo service apache2 restart

2. Change apache virtual host configuration.

<Directory /home/project_dir>
  Options Indexes FollowSymLinks
  AllowOverride None
  Require all granted
  Allow from all
</Directory>

from

AllowOverride None

to

AllowOverride All

3. Now create a .htaccess file into the project root directory then add the following configuration.

RewriteEngine on

RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

4. Finally, Open config.php and do following replaces

$config['index_page'] = "index.php"

to

$config['index_page'] = ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment