#StackBounty: #centos #apache-httpd #url #rewrite URL rewriting for root of website

Bounty: 50

This is an excerpt of the configuration of my Apache 2.4.37 webserver on Centos 8:

RewriteEngine on

RewriteRule ^/$ /index.php [R,L]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9} /(([^/]+/)*([^/.]+)).php[ ?]
RewriteRule .php$ /%1/ [R=301,NC,L]
RewriteRule ^(.*)/$ /$1.php [NC,L]

The second rule block is taken from here and rewrites all URLs https://mysite.com/anypage.php to https://mysite.com/anypage/, hiding PHP file extensions and making permalinks nicer to see.

I’ve added the first rule block after noticing that the URL https://mysite.com/ returned a File not Found. Now it works.

However, a minor annoyance is that https://mysite.com/ redirects to https://mysite.com/index/ (since it loads the file index.php).

My question: How can this configuration be changed so that the URL https://mysite.com/ stays the same?

Get this bounty!!!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.