Question

How do I remove index.php from the URL?

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?


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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.

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