大网数据广告活动
网站运营与故障问答

CNAME: does a cname change the url that the browser displays?

· 52CE 我爱测

I have a web site www.somewhere.com and I want the alias fr.somewhere.com . I set up a CNAME record for www.somewhere.com alias fr.somewhere.com . When a user types in http://fr.somewhere.com in their browser, does the URL in the…

问题原文

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

I have a web site www.somewhere.com and I want the alias fr.somewhere.com.

I set up a CNAME record for www.somewhere.com alias fr.somewhere.com. When a user types in http://fr.somewhere.com in their browser, does the URL in the browser remain fr.somewhere.com or change to www.somewhere.com?

已采纳解答

原帖链接 · Jeff · CC BY-SA 4.0

It will remain fr.somewhere.com by default but it will arrive at the server that handles somewhere.com requests. Inside there, in server's .htaccess, the %{HTTP_HOST} variable will contain fr.somewhere.com for such requests. You can base your resource mapping on that.

If you would want to rewrite it to somewhere.com, you can simply do it like this in .htaccess. as well.

RewriteCond %{HTTP_HOST} =fr.somewhere.com
RewriteRule ^(.*)$ http://www.somewhere.com/$1 [R=permanent,L]

Note, that %{HTTP_HOST} will actually be fr.somewhere.com and if that condition matches, it will redirect (HTTP 301) to www.somewhere.com an append the path $1.

I have a CNAME record created for blog.legoservices.com which just points to tumblr, but all you see is blog.legoservices.com.

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

资料来源与适用范围

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

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

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