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 a subdomain named and another domain named I want my subdomain to always redirect to How to do this? Kindly help

share|improve this question

migrated from Apr 15 '10 at 3:56

This question came from our site for professional and enthusiast programmers.

Are you using IIS or Apache? – Stefan Kendall Apr 13 '10 at 17:13
1 is not a domain name... Neither is – bortzmeyer Apr 14 '10 at 7:00
@bortz - how is that relevant? The answer will still be the same... – Mark Henderson Apr 15 '10 at 4:03
Given that this question didn't originate on SF we need to be a little more forgiving of incorrect and/or misunderstood terminology. – John Gardeniers Apr 15 '10 at 4:13
@Farseeker: because if the question is unclear, the answers will be more difficult to write and less likely to be correct. – bortzmeyer Apr 15 '10 at 6:43

To do all of this, I assume that you have access to the DNS for the domain, OR that the DNS has already been configured.

If the DNS is not configured, you will need to create a record for in your DNS so that it resolves to an IP address (you can do this with either an A or a CNAME record, depending on your purpose).

Then, you will need to set up a website to listen on the IP address you assigned in the DNS, with the hostname You don't state if this is Apache or IIS, so you will need to look up the instructions on how to do that.

After you have a website running on (even if there's nothing in it), then you can tell the browser to redirect when you hit that page. You can do this dozens of ways. You could write a PHP or ASP page that does the redirection (outputting a 302-redirect), or you could do it with Javascript and plain HTML. Hell, you can even do it with a META tag on your HTML page.

Some DNS providers (such as will do this service for you so you don't need to do anything except register the DNS and set up the redirect there, but note that it is NOT the DNS doing the redirect, it's just a value-add service that the DNS provider gives.

share|improve this answer

If you're running Apache, adding lines similar to this to httpd.conf will do the trick:

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteRule ^(.*) $$1 [R=301]

Also make sure this one is present in the file somewhere. It's usually there by default though.

LoadModule rewrite_module libexec/apache22/

Note: Your paths, version number, and domain may be different. With more detail, we can refine this answer to be exactly what you need.

share|improve this answer

Sounds like you need a domain name redirect in your DNS record. More info in this discussion thread:

share|improve this answer
There's no such thing as a "domain name redirect" at the DNS level, there's CNAMEs but they're quite different. – Mark Henderson Apr 15 '10 at 3:58

Your Answer


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