I have problems with choosing a directory by HTTP hostname.
I have a file structure like this:
.
+-- .htaccess
+-- domains
+-- 123456.a12.whatever.net
| +-- .htaccess
| +-- ...
+-- example.org
| +-- .htaccess
| +-- ...
+-- subdomain.example.org
+-- index.html
The .htaccess
file in the root directory looks like this:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)(.*)$
RewriteRule (.*) %{REQUEST_SCHEME}://%2/$1 [R=301,L]
RewriteCond %{DOCUMENT_ROOT}/domains/%{HTTP_HOST} !-d
RewriteRule (.*) $1 [R=404,L]
RewriteCond %{DOCUMENT_ROOT}/domains/%{HTTP_HOST} -d
RewriteRule (.*) domains/%{HTTP_HOST}/$1 [DPI]
Weird thing is that it works for both 123456.a12.whatever.net
and example.org
but not subdomain.example.org
. When I try to access it I get 500 Internal Server Error. I am sure that it is a problem with the .htaccess
as in the subdomain.example.org
is really only the index.html
. Also, the error seems to be in the last line.
RewriteRule ^(?!domain/)(.*)$ domains/%{HTTP_HOST}/$1 [L]