apache virtualhost: Auto subdomain with exception
Posted
by
Ineentho
on Server Fault
See other posts from Server Fault
or by Ineentho
Published on 2012-04-15T10:01:59Z
Indexed on
2012/04/15
11:32 UTC
Read the original article
Hit count: 239
I've been searching for a way to automatically redirect domains to a specific folder, and fond a good answer here on serverfault: Apache2 VirtualHost auto subdomain. (The accepted answer)
So far everything works good, however now I need to add an exception to this. The result I want is this:
http://localhost/ --> E:/websites/
http://specialDomain2/ --> E:/websites/
http://normal1.com/ --> E:/websites/normal1.com/
http://normalDomain.com/ --> E:/websites/normal2.com/
I get the expceted result for the two last domains, but the localhost doesn't work.
I copied the script from the question aboved, and tried to add something like
<VirtualHost *:80>
RewriteEngine On
RewriteMap lowercase int:tolower
# if already rewitten and we have the right path, stop right here
RewriteRule ^(E:/websites/[^/]+/.*)$ $1 [L]
RewriteRule ^localhost/(.*)$ E:/websites/$1 [L] # <-- Added this row
RewriteRule ^(.+) ${lowercase:%{SERVER_NAME}}$1 [C]
RewriteRule ^(www\.)?([^/]+)/(.*)$ E:/websites/$2/$3 [L,E=VHOST_ROOT:E:/websites/$2/]
</VirtualHost>
I thought this would make sense, since I would translate this to
if URL = localhost/*
Do nothing (because of the [L] flag), and use the default document root specified earlier
else
continue
What's wrong with this? Thanks for any help!
© Server Fault or respective owner