1

We have test1.example and we are going to shut that down on server 1.

On server 2 we have test2.example. We are going to assign the CNAME of test1.example to test2.example.

After doing so if someone goes to test1.example/subdirectory/index.html go to test2.example or test2.example/subdirectory/index.html?

  • You'll need to use an HTTP redirect if you want to redirect users to a new URL. DNS alone cannot redirect URLs. – Maximillian Laumeister Jul 25 at 21:48
3

A CNAME is not a redirect. When you use a CNAME, the traffic for both domains is sent to the same IP address. The behavior of the site that users see when you use a CNAME record is identical to what users see when you use an A record with the IP address of the other server. The type of DNS record you use has no bearing on how your site behaves. You can't cause redirects with DNS alone.

It is up to the webserver how to handle traffic for two different domains. The webserver gets sent the host name for each request. The webserver can choose to:

  1. Show the same content for both domains
  2. Show different content for each domain
  3. Show content for one domain and redirect the other domain
  4. Show error messages for one or both domains.

Implementing a redirect for a domain is done through webserver configuration. You don't say which webserver software you are using, so I will just give general instructions. You have to set up two sites or virtual hosts one for each host. Then you need to configure one of them to redirect. That is usually a one line configuration option. For example in Apache, the virtual host configuration for the old site might look like

<VirtualHost *:80>
    ServerName test1.example
    Redirect / http://test2.example
</VirtualHost>

When you configure the redirect, you can choose to redirect to deep URLs or redirect everything to the home page. The Apache configuration shown above does deep redirects. It is almost always better to redirect to deep URLs. It hurts SEO to redirect to the home page of the new site and it confuses users.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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