Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

How do I setup a domain to forward to another domain via DNS or apache?

share|improve this question

3 Answers 3

up vote 0 down vote accepted

The DNS does not know what a redirect is, all it knows is how to assign a domain to a given ip by either using a Canonical name or an IP.

So the first step is to create an A name for the domain you want to redirect in your DNS to the apache server IP:

Let's say your apache server ip is so in the DNS record of the domain you want to redirect you would need to have the follow entries:    IN    A
www            IN    CNAME

Restart/reload your dns server to make the changes apply.

If the domain you want to redirect is being hosted on the same server, it makes things a lot simple on the apache server, all you need to do is to add the domains on the ServerAlias example:

<VirtualHost *:80>
    DocumentRoot /www/domain/public_html 

If the destination domain is not being hosted on the same server then you can do the follow:

<VirtualHost *:80>
    Redirect permanent /

Another option is to use the .htaccess if that given domain is already being redirected to your main domain:

RewriteEngine on
rewritecond %{http_host} ^ [nc]
rewriterule ^(.*)$$1 [r=301,nc] 
share|improve this answer

If the site will serve requests for the domain you want to forward, just create a DNS CNAME record from the forwarded domain to the target domain name.

If the site is a name based virtual host, you may need to also add the forwarded domain name to the VirtualHost section as a ServerAlias.

share|improve this answer
How can I use a cname entry to forward the domain completely? I only want to forward to, ignoring any /index.html or anything past it. – Webnet Aug 28 '10 at 2:40

If you want to forward the domain, set the DNS A record to forward to the server. You should have an MX record for the domain. It should point to a server which will handle your mail, especially for

In apache follow the options Prix gave using short-domain, to do the redirect. The following rewrite ruleset will forward requests from short-domain to long-domain. does not need to be hosted on the same server as short-domain. Use the appropriate domains. If you omit the RewriteCond statement all matching requests will be redirected.

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

These rules would normally be placed in a VirtualHost definition.

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.