1

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?

  • 3
    Just because your hosting service allows custom name servers, it doesn't mean that its a good idea. It is usually better and cheaper to use reputable nameservers that are already running. It is hard to run enough of them yourself, or have them in disparate regions of the globe. Custom name servers under your own domain also necessitate extra glue records. Don't use custom name servers. There is no reason to do so. – Stephen Ostermiller Nov 1 '18 at 14:04
  • 3
    I agree with @StephenOstermiller and you also have to remember/know that there is no concept of "redirection" or "query string" in the DNS worls, those are all concepts in the HTTP world. The DNS for your case just maps names to IP address, this is orthogonal to the fact that there is then an HTTP server running at the end of the IP and that it accepts an URL as input and then does something, either reply with content or does a redirect to another URL. If you do not know how the DNS works, it is not a good idea to start by managing yourself nameservers, use a provider. – Patrick Mevzek Nov 1 '18 at 16:18
2

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 ($_SREVER['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).

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.