www.example.com and example.com can be completely different hosts with different websites, etc.; it is only by convention that they typically point at the same host. When you visit either one, the process goes like this (http://www.example.com/ used as example):
Your browser asks its DNS resolver what the IP address of www.example.com is. The resolver tells it that the IP is 1.2.3.4.
Your browser connects to 1.2.3.4 on TCP port 80 (the default for HTTP), and asks for the path / for the host www.example.com (given in the Host header). The web server returns the document requested.
Your browser repeats the above as necessary to fetch any resources (images, scripts, etc.) needed for the page and renders the page.
Note that the DNS server could return different IP addresses for the different hostnames, or the web server could reply with a different page for each hostname. They typically do not to reduce user confusion, but it is possible.
It is likely that one is faster than the other because the IP address and resources for one are already cached; that is, they have been stored from a previous attempt to access the page, so the browser knows that it does not need to fetch them again.
It is for this and other reasons (e.g. search engine optimization, as g_thorn suggests) that it is often advisable to choose one canonical hostname to use, but there is no intrinsic advantage to either one.
A real Apache/DNS expert (which is not me) can probably answer this better, but one thing I can say is that you should be directing users to either www or non-www, and not have both. You can set a 301 redirect to one via Apache directives (such as in .htaccess).
Having a www and non-www site can be confusing to search engines, and you may run into duplicate content issues. Also, if a site uses any sessions, as users click through your site's links, alternating between www and non-www, their sessions will disappear, as content editors will indiscriminately link to either www or non-www.
I see sites where this happens all the time and users get very confused. I used to get support calls about this regularly on some sites where this was the setup.
就其本身而言,同一域中的特定 DNS 名称不会对速度产生影响。然而,还有许多其他事情可能发生。例如,这些名称可能指向不同的服务器,或者参与 url 重写规则。因此,您需要优化您的服务器,除非您使用某些特定的 dns 策略,否则只需将所有涉及的名称指向该服务器即可。
By themselves, specific dns names in the same domain would not make a difference in speed. However, there are many other things that may happen. For example, those names may point to different servers, or one would participate in url rewriting rules. So you will need to optimize your server and, unless you use some specific dns strategy, just point all involved names to that server.
发布评论
评论(3)
www.example.com
和example.com
可以是完全不同的主机,具有不同的网站等;按照惯例,它们通常指向同一主机。当您访问其中任何一个时,过程如下(以 http://www.example.com/ 为例):www.example.com
的 IP 地址是什么是。解析器告诉它 IP 是1.2.3.4
。1.2.3.4
,并请求主机www.example.com< 的路径
/
/code>(在主机标头中给出)。 Web 服务器返回所请求的文档。请注意,DNS 服务器可以为不同的主机名返回不同的 IP 地址,或者 Web 服务器可以为每个主机名回复不同的页面。它们通常不会减少用户的困惑,但这是可能的。
其中一个可能比另一个更快,因为其中一个的 IP 地址和资源已经缓存;也就是说,它们是在上次尝试访问该页面时存储的,因此浏览器知道不需要再次获取它们。
正是出于这个原因和其他原因(例如,搜索引擎优化,如 g_thorn 所建议的),通常建议选择一个规范主机名来使用,但这两者都没有内在优势。
www.example.com
andexample.com
can be completely different hosts with different websites, etc.; it is only by convention that they typically point at the same host. When you visit either one, the process goes like this (http://www.example.com/ used as example):www.example.com
is. The resolver tells it that the IP is1.2.3.4
.1.2.3.4
on TCP port 80 (the default for HTTP), and asks for the path/
for the hostwww.example.com
(given in the Host header). The web server returns the document requested.Note that the DNS server could return different IP addresses for the different hostnames, or the web server could reply with a different page for each hostname. They typically do not to reduce user confusion, but it is possible.
It is likely that one is faster than the other because the IP address and resources for one are already cached; that is, they have been stored from a previous attempt to access the page, so the browser knows that it does not need to fetch them again.
It is for this and other reasons (e.g. search engine optimization, as g_thorn suggests) that it is often advisable to choose one canonical hostname to use, but there is no intrinsic advantage to either one.
真正的 Apache/DNS 专家(不是我)可能可以更好地回答这个问题,但我可以说的一件事是,您应该将用户定向到 www 或非 www,而不是两者兼而有之。您可以通过 Apache 指令(例如在 .htaccess 中)将 301 重定向设置为 301 重定向。
拥有 www 和非 www 网站可能会让搜索引擎感到困惑,并且您可能会遇到重复内容的问题。此外,如果网站使用任何会话,当用户点击您网站的链接(在 www 和非 www 之间交替)时,他们的会话将消失,因为内容编辑器将不加区别地链接到 www 或非 www。
我看到网站上经常发生这种情况,用户感到非常困惑。我曾经在一些设置了此设置的网站上定期接到有关此问题的支持电话。
A real Apache/DNS expert (which is not me) can probably answer this better, but one thing I can say is that you should be directing users to either www or non-www, and not have both. You can set a 301 redirect to one via Apache directives (such as in .htaccess).
Having a www and non-www site can be confusing to search engines, and you may run into duplicate content issues. Also, if a site uses any sessions, as users click through your site's links, alternating between www and non-www, their sessions will disappear, as content editors will indiscriminately link to either www or non-www.
I see sites where this happens all the time and users get very confused. I used to get support calls about this regularly on some sites where this was the setup.
就其本身而言,同一域中的特定 DNS 名称不会对速度产生影响。然而,还有许多其他事情可能发生。例如,这些名称可能指向不同的服务器,或者参与 url 重写规则。因此,您需要优化您的服务器,除非您使用某些特定的 dns 策略,否则只需将所有涉及的名称指向该服务器即可。
By themselves, specific dns names in the same domain would not make a difference in speed. However, there are many other things that may happen. For example, those names may point to different servers, or one would participate in url rewriting rules. So you will need to optimize your server and, unless you use some specific dns strategy, just point all involved names to that server.