This is a discussion on Redirecting your visitors to the preferred form of your URL using JavaScript within the Web Design forums, part of the Web Designing & Development category; Do you have multiple entrances to your site and looking for a client-side solution that can redirect your visitors to ...
Do you have multiple entrances to your site and looking for a client-side solution that can redirect your visitors to the preferred entrance?
For example, you may have multiple domain names pointing to the same site -- domain_a.com, domain_b.com and domain_c.com. Although you want to keep all of your domains either because you want to reserve those names, because your marketing department convinced you that having multiple names pointing to the same site will attract more visitors or some other reason, you may prefer that the visitors end up at the same domain. You may want to redirect visitors from domain_b.com and domain_c.com to domain_a.com for example.
Above code will check if domain_a.com is a part of the current URL. If not, it will automatically redirect the visitor to http://domain_a.com. One of the advantages is that this code will work even if you have a single version of your home page that has multiple domain names pointing to it.Code:<script type="text/javascript" language="JavaScript"> <!-- if( -1 == location.href. toLowerCase(). indexOf('domain_a.com') ) { location.href = 'http://domain_a.com'; } // --> </script>
Bookmarks