1

First, yeah, I know, this question is probably a duplicate, but I've searched for some hours now and I can't find any relevant answer.... So I try asking.

I got, let's say, domain-a.com & domain-b.com. domain-a is just an alias of domain-b.com, and everything (root & subdomains) should redirect to it. So I'd like the following redirections:

http://domain-a.com => http://domain-b.com
http://aze.domain-a.com => http://aze.domain-b.com
http://www.domain-a.com => http://www.domain-b.com

I need also the browser to display domain-b.com, so domain-a.com should never appear anywhere when accessing the domain name...

Ok, so far, yeah, that's pretty easy using A-records & redirections using nginx or Apache. But I'd like to do all of this using only my DNS settings (through the OVH pannel), so I'll just have to handle domain-b.com on my own server.

What I've tried:

  • using a CNAME record like this on domain-a.com: * IN CNAME domain-b.com., but when I go to aze.domain-a.com, the URL is not changed, and the root domain is not handled.
  • using 301 redirections, but I have to configure every subdomains, and I don't know which subdomains will be used in advance.

It seems that DNAME record is appropriated to my needs, but I can't set up one with OVH. So, if this is the right record to use, I'll have to transfer my domain to another registrar, so I prefer being sure before doing that.

I got another constraint: my server handles several domain names, so I can't catch every requests to redirect to domain-b.com equivalent, and I'd like to configure only domain-a.com.

So, is that possible ?

Thank you for your help

1 Answers1

2

The only way to do redirection of a web request is using a web server. When a DNS resolver, like the one built into a user's system, requests an address, it gets an address. A CNAME just tells it the other place to get the address from, but it wants an address, period. It will then initiate a request to the web server for the domain it asked for, using the address it got as a means to initiate the TCP connection. There is no connection between your browser and your DNS resolver. Therefore, what you are asking for is not possible in a pure DNS scenario, even using DNAME (which is just CNAME on a bigger scale).

I am not familiar with the configuration of nginx, but in apache, you can create a virtual host to service domain-b. The top virtual host acts as a "catch-all" for any other way the site is accessed. You can redirect all those catch-alls to domain-b using some rewrite rules. So you can capture aze.domain-x.com, or aze.domain-y.com, etc, and grab the host part and redirect it to aze.domain-b.com. You'll have to use some regex, etc, but it's the right way to do it. See Apache 2.4 Redirecting and Remapping with mod_rewrite. I'm sure nginx has the same functionality, though perhaps executed in a different way.

theglossy1
  • 291
  • 2
  • 7
  • Thank you for your explanation! Gonna do some virtual hosts then – Alexandre Germain May 25 '17 at 15:11
  • This, you'll need to keep those domains and systems around unless you are satisfied with 301, you can check referrals to see what traffic still comes from old hostnames. You can also check with your domain registrar, many of them have this additional forwarding option, such as godaddy. – Jacob Evans May 25 '17 at 15:13