When a user goes to the base domain http://www.domain.com/ or http://domain.com/,
the page has to be redirected to http://www.domain.com/#!/news.html
I mean something like this:
if (window.location.href("http://www.domain.com/") || window.location.href("http://domain.com/")) {
window.location.replace("http://domain.com/#!/news.html");
}
This won’t work. Especially, the page is provided on two different domains.
any ideas how to solve it in pretty Javascript or jQuery (using jQuery 1.4.2)?
Use the parsed-URL properties on
location, likepathname,hostname,searchandhashrather than trying to mess with thehref:It’s best for SEO to put your site on only one particular hostname, and redirect any other associated hostnames to that canonical hostname. Let the HTTPD config worry about domains instead of your app. For example if you chose
www.domain.comto be your canonical hostname, in Apache config you could say:Other web servers have a different ways of setting up redirects. If you have no access to the Apache config and you’re limited to
.htaccess(ugh) then you’d have to usemod_rewriteto do a conditional redirect based on the hostname.