Reputation: 744
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?
Upvotes: 0
Views: 2954
Reputation: 9211
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 the LAST
modifier/flag for rewrite rule:
RewriteRule ^public/(.*)$ public/$1 [L]
RewriteRule ^(.*)$ public/$1
Just in case you would like to know the way of debugging the rewrite_module, you can set LogLevel DEBUG
in httpd.conf, then you can check on the apache error log.
Upvotes: 1