Domain – Using a CNAME record to redirect a subdomain to another website

cname-recorddomaindomain-name-systemsubdomainwebsite

Under my current understanding, I am able to use CNAME records to redirect users to another domain. For example, I own 'mydomain.com'. When a user goes to 'keep.mydomain.com', they should be redirected to 'keep.google.com'.

I currently have the following record in my DNS record set:
Name: keep.mydomain.com
Type: CNAME
Value: https://keep.google.com/
TTL: 300ms

I don't have any other records under that subdomain, however I do have MX, A, NS, SOA, TXT, and other CNAME records under other domain/subdomains, which work properly. However, when I go to 'keep.mydomain.com', I get the error:

This site can’t be reached
keep.mydomain.ca’s server DNS address could not be found.
ERR_NAME_NOT_RESOLVED

Am I misunderstanding the use of CNAME, or is there something I have configured that is conflicting?

Best Answer

CNAMES are not redirections, they are aliases. CNAME also includes all other resource records such as A,MX,TXT.

so if you query for an A record, the cname will send you to the A record of it's alias.

Many registrars include additional options such as redirect services, godaddy and Google for example.

also, be careful entering values for CNAMES, some systems assume terminating periods, others do not.

assuming domain example.com

test IN CNAME example.org

results in test resolves to the IP of host example.org.example.com which does not exist.

test IN CNAME example.org.

results in test resolves to the IP of host example.org which does exist.

CNAME values can only be HOSTS, not a URL.

dig A keep.richardyang.ca @8.8.8.8
keep.richardyang.ca.    299     IN      CNAME   https://keep.google.com/.

Change it to

keep.richardyang.ca.    299     IN      CNAME   keep.google.com.

Maybe check out https://stackoverflow.com/questions/10115799/set-up-dns-based-url-forwarding-in-amazon-route53

Example on how to use Synthetic records with Google.com Domains.

Keep Record

;; ANSWER SECTION:
keep.jacobdevans.com.   3600    IN      CNAME   ghs.googlehosted.com.
ghs.googlehosted.com.   163     IN      A       173.194.207.121

This sends my request to google's servers, google then sends a 302 code to the new url, I've chosen 302, you would want 301 if you want SEO to know this is a permanent change, I may want to switch my destinations at a later time as I use this for my signature links to ensure my contact info stays current.

OR, since you already have a website, point the domain there and redirect the site.

Script:

<script type="text/javascript">
if (window.location.href== "http://keep.richardyang.ca") {
   window.location.href = 'http://keep.google.com'; 
}
</script>

DNS:

keep.richardyang.ca.    299     IN      CNAME   richardyang.ca.