大网数据广告活动
服务器运维问答

Redirect root & all subdomains to another domain equivalent (DNS only)

· 52CE 我爱测

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 o…

问题原文

原帖链接 · Alexandre Germain · CC BY-SA 3.0

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

已采纳解答

原帖链接 · theglossy1 · CC BY-SA 3.0

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.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-05-25)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。