我会遇到一个问题,如果我访问了我要通过 www.example.com/page 然后浏览器无法初始化网络工人。
根据我的阅读,这是出于安全目的的预期行为。很好,但是我预计有些人会通过
我认为这样做的简单方法是更改 www.example.com 从 @ record到cname记录,将所有调用重定向到 https://www.example.com/page 而不是 https://example.com/page
我昨晚做到了,旧记录的TTL只有30m,所以甚至到目前为止,世界上最慢的DNS缓存应该已更新。
但是,如果我尝试通过 www.example.com 。
我在这里想念什么?最重要的是,我该如何完成这项工作?
I'm getting an issue where if I access a website I'm making via www.example.com/page then the browser fails to initialize the web workers.
From what I've read this is expected behaviour for security purposes. And that's fine, but I anticipate some people will be coming to the site via www.example.com while others will just type in example.com, and I'll need both to be able to access all the site's resources.
I figure the easy way to do this is to change www.example.com from an @ record to a CNAME record, redirecting all calls to https://www.example.com/page instead to https://example.com/page
I did that last night, and the TTL on the old record was only 30m, so even the world's slowest DNS caches should have been updated by now.
But if I try to access the site via www.example.com I'm still getting the same domain origin error.
What am I missing here? And most importantly, how can I make this work?
发布评论
评论(1)
CNAME记录不是HTTP重定向。
浏览器寻找
www.example.com
,对其进行DNS查找,并告诉基础DNS客户端,IP地址与example> example.com '相同S,因此它获取
示例
的IP地址,然后向该IP地址提出http请求,要求www.example.com
。Origin
仍然是https://www.example.com
。将您的HTTP服务器配置为发行
301,以永久移动
重定向www.example.com
而不是。CNAME records are not HTTP redirects.
The browser looks for
www.example.com
, makes a DNS lookup for it, and the underlying DNS client gets told that the IP address is the same asexample.com
's, so it getsexample.com
's IP address and then makes an HTTP request to that IP address asking forwww.example.com
.The
origin
will still behttps://www.example.com
.Configure your HTTP server to issue a
301 Moved Permanently
redirect for any requests forwww.example.com
instead.