开发者

What is the difference between typing www.[site].com and [site].com? [closed]

Closed. This question is off-topic. It is not currently accepting answers.

Want to improve this question? Update the question so it's on-topic for Stack Overflow.

开发者_C百科

Closed 11 years ago.

Improve this question

I'm testing my website to try and optimize it for speed using http://tools.pingdom.com. I've noticed that typing www. makes for sometimes significant speed changes. Why is this?


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):

  1. 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.
  2. 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.
  3. 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜