Question

How do I remove index.php from the URL?

Posted June 11, 2015 16.8k views
UbuntuApachePHP

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]
</IfModule>

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?

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
2 answers

Hi!

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

my first website of url in no index.php butt my secound and third website off url index.php problem please help

The url of my first website is not index.php but how do I remove index.php in the URL of the second and third website.

Submit an Answer