大网数据广告活动
网站运营与故障问答

How to redirect domain names which use my custom name servers?

· 52CE 我爱测

My web hosting service allows setting custom name servers. For example, if my website is http://www.example.com/ , I can set custom name servers ns1.example.com and ns2.example.com . When other domain names use my custom name ser…

问题原文

原帖链接 · Ian Y. · CC BY-SA 4.0

My web hosting service allows setting custom name servers. For example, if my website is http://www.example.com/, I can set custom name servers ns1.example.com and ns2.example.com.

When other domain names use my custom name servers, how do I redirect their visitors to a specific page of my website and also remember the source domain names by using the query string? For example, if a domain name randomdomainname.example uses my custom name servers, how do I redirect its users to http://www.example.com/welcome.php?source=randomdomainname.example?

已采纳解答

原帖链接 · MrWhite · CC BY-SA 4.0

The "custom nameservers" that some hosts allow you to configure for your domain are usually just an alias for the hosts primary nameservers, pointing to the same IP address. As @Stephen pointed out in comments, this requires you to manually configure glue records that point to this IP address (although the host may do this for you, if the registrar and host are one and the same).

The main reason for custom nameservers is to obfuscate the true DNS provider / host. This is a "white label" solution, primarily aimed at resellers that want to "hide" the true host they are reselling on behalf off, to make it look as if they are really the provider. However, this is only a superficial layer of obscurity as anyone can do a reverse lookup on the IP address to find the real provider.

An additional caveat with using "custom nameservers" of this nature is that if the IP address of the host's nameservers should ever change then you will need to manually update the glue records.

When other domain names use my custom name servers, how do I redirect their visitors to a specific page of my website

As @Patrick mentioned in comments, these "custom nameservers" have nothing to do with redirection. The NAMESERVER ("custom" or not) simply informs the requesting user-agent of the IP address to use in sending the request. This doesn't necessarily have anything to do with your domain name or your website.

and also remember the source domain names by using the query string?

In order for randomdomainname.example to map to your hosting account (ie. example.com) you need additional directives (eg. ServerAlias) in the server config so that your account will respond to requests for this domain. In cPanel (for example) this is an "Addon domain" or "Domain Alias".

Once you've created the Addon domain in your account then you can examine the Host HTTP request header (e.g. $_SERVER['HTTP_HOST'] in PHP) to determine which host has been requested (no need to use a query string or create a redirect).

However, if randomdomainname.example points to an entirely different account on the server (remember the NAMESERVER only tells you which server the account resides on) then any redirect back to example.com needs to be created on that other account in the same way you'd create any redirect (by returning a 3xx status and a Location header).

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

资料来源与适用范围

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

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

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