How do I remove index.php from the URL?

June 11, 2015 1.7k views
Apache PHP Ubuntu

I have a project where everything on the website is routed via index.php and the way my app is designed, index.php can be removed from the URL safely. So, /index.php/inbox?from=23 can safely be converted to /inbox?from=23.

I need the rewrite rule (Apache 2.4) for doing so. There is a constraint though - I do not want to do it via .htaccess file, but from the host configuration file (/etc/apache2/sites-available/000-default.conf) only. On my development machine, I have the following:

<IfModule mod_rewrite.c>
    # Rules to serve URLs which point to files directly
    # ----------
    RewriteEngine On
    RewriteBase /
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(.*)$ index.php/$1 [L]

But this is not working on the server. (I know that RewriteBase is not allowed in the configuration file itself, but removing it does not work either).

What should I do?

1 Answer


Because you have an <IfModule ..> tag, Apache will completely skip over that block if the Rewrite module is disabled without showing any errors or messages in the logs. Enable the module and restart Apache:

sudo a2enmod rewrite
sudo service apache2 restart
Have another answer? Share your knowledge.