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

So this is my scenario:

I have 1 static IP and 2 servers. 1 server is a web server the other is a mail server. I have a router as a hardware firewall with all the ports are set that require passthrough to internal ip addresses .

If a user types the url they see that website. If the user wants to access webmail they type in the url but still see

I have set the webmail domain to be accessible via port 8080 on the mail server and if the user types the url it works no problem but not with

So this is my issue:

In my httpd.conf I want to setup a Redirect 301 so that when the user types in they get redirected to

I'd prefer not to use .htaccess and keep the directives in the httpd.conf


share|improve this question
up vote 1 down vote accepted

You'll need to create a virtual host on your main web server that responds to web requests for the "" address. Take a look at the Name-based Virtual Host documentation on the Apache website. You'll also need a mod_rewrite rule to do the redirection. Your configuration would look something like this:

NameVirtualHost *:80
<VirtualHost *:80>
  RewriteEngine On
  RewriteRule (.*)\1 [R=301,L]
share|improve this answer
Rewrite is useless if a virtualhost is created, RedirectMatch will be probably faster – radius Jun 20 '10 at 18:22
what are you talking about radius? Rewrite is perfectly fine in a virtualhost as listed above. The code is a little broken (use $1 not \1) but other than that it's good. – troyengel Jun 21 '10 at 9:43

There is at least 2 way to do this:

  1. Create 2 virtual host one for and one for and then put your RedirectMatch directive in the second one.
    You could also use the ProxyPass directive in the virtual host to make it working like a reverse proxy and have working directly without redirection

  2. Use mod_rewrite like this to only redirect for the url with a rule like that

    RewriteCond %{HTTP_HOST} ^$ [NC]
    RewriteRule ^(.*)$1 [R=301]

    with mod_rewrite you can also do a reverse proxy with a rule like ( should resolve to the internal IP)

    RewriteCond %{HTTP_HOST} ^$ [NC]
    RewriteRule ^(.*)$1 [P]

share|improve this answer

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.