How to remove index.php from url | aws | ubuntu 16.4 | codeigniter


I have uploaded my codeigniter project on AWS  instance of ubuntu 16.4

But tried all required settings, still not able remove index.php from urls.

Is there anything extra need to be done other than config setting and  .htaccess file modification??

Asked on October 10, 2018 in Programmer.
Add Comment
1 Answer(s)
Best answer

Yes!  As you are using virtual server, so it’s require check if  mod_rewrite is enabled or not.

First, we need to activate mod_rewrite. It’s available but not enabled with a clean Apache 2 installation.

sudo a2enmod rewrite

This will activate the module or alert you that the module is already enabled. To put these changes into effect, restart Apache.

sudo systemctl restart apache2

mod_rewrite is now fully enabled. In the next step we will set up an .htaccess file that we’ll use to define rewrite rules for redirects.

We will need to set up and secure a few more settings before we can begin.

By default, Apache prohibits using an .htaccess file to apply rewrite rules, so first you need to allow changes to the file. Open the default Apache configuration file using nano or your favorite text editor.

sudo nano /etc/apache2/sites-available/000-default.conf

Inside that file, you will find a <VirtualHost *:80> block starting on the first line. Inside of that block, add the following new block so your configuration file looks like the following. Make sure that all blocks are properly indented.


<VirtualHost *:80>

<Directory /var/www/html>

Options Indexes FollowSymLinks MultiViews

AllowOverride All

Require all granted


. . .


Save (ctrl+o) and close (ctrl+x) the file. To put these changes into effect, restart Apache.

sudo systemctl restart apache2

Now create .htaccess file and write below code


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


Answered on October 10, 2018.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.