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

I have setup a domain, I and I would like to point that domain onto a different webserver.

lets say:

domain 1: on server 1

domain 2: on server 2

I would like to forward to, and I have tried to do that with setting up a virtual host on server 2 and mod_rewrite.

The virtual host looks like this:

   <virtualhost XXX.XXX.XXX.XXX:80>
            ServerAlias *    
            RewriteEngine On
            RewriteCond %{HTTP_HOST} (.*)\test\.com
            RewriteRule ^(.*)$1 [R=301,L]

Everything works fine except that does not redirect.

Question 1: How would I go about redirecting all requests (subdomains everything) that come into to using mod_rewrite.

Question 2: do I need to specify a directory in this case for the virtual host?

Question 3: do I need the ServerAlias or is it counter productive here?


Ended up with doing a 301 with following setup

<virtualhost <ip>:80>
        Redirect 301 /
share|improve this question
up vote 2 down vote accepted

DocumentRoot is not required. You can set up vhosts like this without any problems:

 <VirtualHost xx.xx.xx.xx:90>
  ServerName domain.tld
  ServerAlias www.domain.tld
  RedirectPermanent /

This will redirect all requests to the main site but also subfolders. E.g. www.domain.tld/foo/bar will be redirected to

ServerAlias is only required if you want several hostnames.. Such as both www and without www.

share|improve this answer
yes that is what I want, but just with a 301 thanks :-) – mahatmanich Jun 18 '11 at 16:20
FYI, the "RedirectPermanent" does a 301 redirect. To be sure that all requests to subfolders are redirected as well, append a slash to the URL in your redirect line. – Frands Hansen Jun 19 '11 at 8:23
how about all subdomains? – mahatmanich Jun 19 '11 at 18:05

You have mixed up .com and .de in your example configuration. Could this be the problem?

Question 1:

RewriteCond %{HTTP_HOST} ^.*\.test1\.de [NC]
RewriteRule ^(.*)$$1 [L,R=301]

Question 2:
I'm not a 100% sure if a DocumentRoot is required or not, but I think no.

Question 3: Yes, you need the * Alias.
It might work without it if this VirtualHost is your first VirtualHost.
It would then get all requests that did not match any other VirtualHosts as it is the default.
However it's cleaner to configure it.

share|improve this answer
should be all com sorry. that is not the issue – mahatmanich Jun 18 '11 at 15:06

Try something like this in your virtualhost:

<Virtualhost XXX.XXX.XXX.XXX:80>    
     ServerAlias *
     Redirect 301 /

Very basic and should transfer anything regardless of what url the user is trying to access from to

share|improve this answer
it does redirect, but does not redirect – mahatmanich Jun 18 '11 at 16:11
it's missing ServerAlias * – faker Jun 18 '11 at 16:15

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.