I would like to type the following url into my browser:
localhost/mydomain/about.php
And have apache redirect to the actual file location:
localhost/mydomain/public_html/about.php
I wrote the following .htaccess file:
RewriteEngine On
RewriteRule ^(.+)$ public_html/$1
I’m totally unfamiliar with Apache and my understanding of reg expressions is very basic – but I thought this would mean “Take any path after the domain name and stick public_html/ in front of it”. The result, however, is a 500 Internal Server error.
What am I missing?
This is because specifying only
^(.+)$rule will keep the rewrite in an infinite loop.about.php > public_html/about.php > public_html/public_html/about.php > …
A quick fix would be
RewriteRule ^([^/]*)$ public/$1. or you might be interested with theLASTmodifier/flag for rewrite rule:Just in case you would like to know the way of debugging the rewrite_module, you can set
LogLevel DEBUGin httpd.conf, then you can check on the apache error log.