最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Is there really a difference between http:example.com and www.example.com? - Stack Overflow

programmeradmin4浏览0评论

I seem to have stuck in this weird issue. If I open my website by giving the address as , it opens up fine. But if I enter the address as www.example or , then the site opens as if the browser is JS disabled (and without any CSS formatting).

I tried in IE, Firefox and Chrome. The issue occurs consistently.

Is there really any difference between and www.example?

If yes, then is there any way to give a consistent experience to the user irrespective of how he landed on the site? Maybe, by redirecting him to the http site even if he used just www.

I seem to have stuck in this weird issue. If I open my website by giving the address as http://example., it opens up fine. But if I enter the address as www.example. or http://www.example., then the site opens as if the browser is JS disabled (and without any CSS formatting).

I tried in IE, Firefox and Chrome. The issue occurs consistently.

Is there really any difference between http://example. and www.example.?

If yes, then is there any way to give a consistent experience to the user irrespective of how he landed on the site? Maybe, by redirecting him to the http site even if he used just www.

Share Improve this question edited Sep 20, 2014 at 22:48 Stephan Muller 27.6k18 gold badges86 silver badges127 bronze badges asked Dec 20, 2012 at 2:51 JanaaaaJanaaaa 1,4261 gold badge17 silver badges35 bronze badges 7
  • 3 Are you sure that http://www.mysite. works but www.mysite. doesn't? Those two should be absolutely identical. – John Kugelman Commented Dec 20, 2012 at 2:54
  • You will need to be a little more specific if you'd like to know about redirection. You can redirect using only JS, but there are nicer ways if you're using say IIS or PHP or something like that. eg. We're using IIS7 here with a URL rewrite to redirect people to www. – Nathan Commented Dec 20, 2012 at 2:55
  • @Nathan: I don't use IIS or PHP. My site is hosted by inmotion. They provide support to both of these but I might not be able to immediately learn and do it that way. Can you tell me the JS way so that I can do a quick fix (atleast temporarily) ? – Janaaaa Commented Dec 20, 2012 at 3:05
  • @John: I too thought so but it turns out to be incorrect. The answer from Kolink explains the reason. – Janaaaa Commented Dec 20, 2012 at 3:08
  • 1 @Ramnath Without being too tricky, this should be fine if (window.location.hostname == "www.mysite.") { window.location.hostname = "mysite."; }. Run that on each page you want to redirect. The down-side is that they need to have Javascript enabled, so your best bet is still to contact the hosting provider and ask for their assistance. – Nathan Commented Dec 20, 2012 at 3:49
 |  Show 2 more ments

3 Answers 3

Reset to default 11

Yes. www.example. is a subdomain of example.. Typically they are the same site, but not necessarily. Some servers will only accept one or the other. Others (like mine) will redirect www.domain.tld to domain.tld for easier cookie handling. Others still (very few) host pletely different websites.

Try redirecting www.mysite. to mysite.. You can achieve this by modifying your .htaccess file. This is also good for search engine optimization since as far as search engines are concerned, the two are separate entities. By redirecting, you are telling the search engines that both are the same.

Although most out-of-the-box vhost configurations will treat the two the same, you can specifically set it to behave as 2 different sites.

发布评论

评论列表(0)

  1. 暂无评论