DNS redirect domain.com at www.domain.com

I did a web search on this, but was completely disappointed with the results. The point is to redirect all requests to the .com domain to the www.domain.com subdomain.

So what I have:

  • www.domain.com - the main domain of the website, all client requests should be redirected here
  • domain.com is another entry point to the website for people who do not use the www prefix, all requests should be redirected to www.domain.com
  • mydomain.com - an alternative site alias, all requests should be redirected to www.domain.com
  • www.mydomain.com - for people using the www prefix, all requests should be redirected to www.domain.com

I understand that this is possible using .htaccess and PHP. But I want to find out how this can be done using only DNS. I also understand that the result of a DNS query does not change what is happening at the HTTP level, so the domain name originally entered will always be the one that was sent to the web server in Host. Therefore, to rewrite domain.com to www.domain.com, I still need Apache mod_rewrite. But I want to do most of the work with DNS (CNAME and A records).

So, the main question is that CNAME and A record each of the above domains?

+44
redirect dns cname
Mar 02 '13 at 8:22
source share
1 answer

You can make Adomain.com record A and all other CNAME domain names at www.domain.com. But this only "decides" that if the IP address of www.domain.com changes, you do not need to change another DNS channel, since they are aliases.

Thus, at the DNS level, there is no way to force redirects. And for a good reason, because DNS is used for more than just HTTP. For example, if the entire request for domain.com is redirected to www.domain.com, your email addresses will be changed to user@www.domain.com.

So, for HTTP redirection you will need to use an HTTP solution. It can be at the web server level (mod_rewrite, in code, javascript (ugh), etc.), but you can also have a proxy in front of your web server to handle this.

+39
Mar 02 '13 at 8:28
source share



All Articles