1

I would like to display the same content of: example.com if someone visits example.net

I researched and it seems to be possible by simply setting up a CNAME record on example.net that is pointing to example.com.

I did exactly that, and this is how my setup looks like right now:

enter image description here

The problem I'm experiencing though is that when I visit example.net I see the default Nginx page of the server that is hosting example.com.

Why is that? Do I need to set things up on server side as well, to point to the same domain? It's quite confusing to me, what's the reason of CNAME then. I could use an A record for that also.

What am I missing here?

Esa Jokinen
  • 43,252
  • 2
  • 75
  • 122

2 Answers2

0

CNAME only works for the same domain, for cross-domain redirection you need a web server to do the actual redirects.

bviktor
  • 756
  • 5
  • 12
  • A `CNAME` doesn't do the HTTP redirect even if it's for the same domain. The web server always needs to be configured to handle the hostname. It could be an alias for the virtual host, a reverse proxy to the other site or a HTTP redirection, but the web server always needs to be aware of it, unless it's a HTTP 1.0 style server, where a single `IP:port` can only server a single site. But we aren't in the 1990s anymore. – Esa Jokinen Mar 10 '20 at 16:33
  • I didn't say a CNAME does a HTTP redirect, hth. – bviktor Mar 10 '20 at 21:28
  • 1
    But CNAME can perfectly fine refer to a hostname from another domain, so this is not true, and not the cause for the problem. – Esa Jokinen Mar 11 '20 at 03:12
0

The web server isn't configured to serve that site when the browser asks for example.net: the host name on the address bar is sent to the server in a HTTP header Host: example.net. This doesn't happen on the DNS level, so it doesn't matter whether it's a direct A or a CNAME-to-A that points to the server.

If you literally want the server to show the same site, you should configure your web server's name based virtual host to have the other domain as an alias. We don't know what server software you are using, but Apache has ServerAlias, Nginx can have multiple hostnames in server_name, and IIS has bindings. Also, every link and resource on the site should use relative paths, or the user will eventually be browsing example.com. That might be hard, as e.g. WordPress always uses absolute paths, and using relative paths and serving the same site on several domains might not be good for SEO.

Better alternative would be using a HTTP redirect. This could be done on the same server, but also on any server example.net A is pointing to. The server at example.net tells the browser to go to example.com, and the URL on the address bar changes. Again, the configuration depends on the server software: Apache has Redirect, Nginx return, and IIS's httpRedirects can be configured in GUI.

Esa Jokinen
  • 43,252
  • 2
  • 75
  • 122
  • What I've seen a 301 Permanently Moved seems to be the standard implementation for these kinds of things. It's also a good way of doing it, since it's cacheable, and you don't need to maintain a complicated rewrite ruleset for both domain names. – Stuggi Mar 11 '20 at 10:08
  • 1
    @Stuggi: Good addition. That's correct. – Esa Jokinen Mar 11 '20 at 10:32