2
votes

I've got a wildcard DNS record, allowing all forms of *.domain.com, additionally I'm pointing several different domains at the same machine and using rewrite rules to direct requests to sub folders depending upon the url the request originates.

For instance domain1.com point to /sites/folder/domain1, domain2.com points to /sites/folder/domain2

My problem is, that i'm using the Apache var HTTP_HOST in this rule, which includes the sub domain so that sub1.domain1.com points to /sites/folder/sub1.domain1.com and with several hundred sub domains for each domain there is no way to create all those folder possibility.

My question: how to remove all sub-domains from the HTTP_HOST variable? This is what the ruleset looks like thus far:

RewriteRule ^file.xml$ sites/%{HTTP_HOST}/file.xml [L]

Which works, until a sub domain is included in the URL...

2

2 Answers

1
votes

To limit your rule to just mydomain.com (ie no subdomains) add a RewriteCond directive before the Rewrite as below

RewriteCond %{HTTP_HOST} ^[^\.]+\.com$ [NC]
RewriteRule ^file.xml$ sites/%{HTTP_HOST}/file.xml [L]

Edit: Allow any domains, but no subdomains

0
votes

I think what he wants is to use the variable HTTP_HOST in a rewrite, but NOT with a subdomain:
HTTP_HOST = www.example.com
Rewrite rule:
RewriteRule ^file.xml$ sites/%{HTTP_HOST}/file.xml [L]
is, in actuality:
RewriteRule ^file.xml$ sites/example.com/file.xml [L]
but NOT:
RewriteRule ^file.xml$ sites/www.example.com/file.xml [L]
-Brian