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
.
-
3
Are you sure that
http://www.mysite.
works butwww.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
3 Answers
Reset to default 11Yes. 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.