Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

What would the rewrite rule be to change subdomain.domain.tld to domain.tld/subdomain?

Or should I look at a VirtualServer directive to take subdomain.domain.tld and serve it from a DocRoot that happens to be also found at domain.tld/subdomain?

And where would the rewrite rule want to live, if using a rewrite is more appropriate?

update - found the link here:

share|improve this question

migrated from Aug 3 '10 at 2:44

This question came from our site for computer enthusiasts and power users.

up vote 1 down vote accepted

No you don't need to setup a virtual server, just use this rule :

RewriteEngine on
RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.tld$
RewriteRule ^/(.*)$ http://domain.tld/%1/$1 [L,R]
share|improve this answer
quick follow-up.. where does the rewrite rule go? – warren Aug 3 '10 at 14:31
found it - – warren Aug 3 '10 at 19:38
@nahar - thanks for the rewrite rule, this is precisely what I wanted! – warren Aug 4 '10 at 13:33

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.