大网数据广告活动
服务器运维问答

Using a CNAME record to redirect a subdomain to another website?

· 52CE 我爱测

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 cur…

问题原文

原帖链接 · juggling_pro · CC BY-SA 3.0

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?

已采纳解答

原帖链接 · Jacob Evans · CC BY-SA 3.0

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.

;; 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.

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

资料来源与适用范围

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

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

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