Click here to Skip to main content
Licence 
First Posted 29 Oct 2001
Views 63,477
Bookmarked 14 times

Domain redirect using JavaScript

By Marco Ascensão | 29 Oct 2001
How to Redirect a Domain to a file or directory using JavaScript

1

2

3

4
1 vote, 100.0%
5
4.00/5 - 3 votes
μ 4.00, σa 5.00 [?]

Introduction

  • Use this script inside the <HEAD> </HEAD> tags of the index.html / index.htm (Apache) or default.htm / default.asp (IIS/PWS) file to redirect the Domains to their respective web page.
  • Initialize the dnsX variables with the Domains you wish to redirect and change their respective location.href
  • Last but not least, in the <BODY> tag call the JavaScript function using the "OnLoad" event: <BODY onLoad="gotoPage()">

Domain redirect using JavaScript

<script language="JavaScript">
<!--
function gotoPage()
{
    var dns1 = "natura-travel.com"
    var dns2 = "montepe-club.com"
    var dns3 = "natura-act.pt"
    var dns4 = "levadas-veredas.com"
    var dns5 = "madeirawalks.com"
    var dns6 = "nature-walks.com"
    var urlloc = location.href
    var loc = urlloc.toLowerCase()

    if (loc.indexOf(dns1) != -1)
        location.href="http://www.Natura-Travel.com/natura-travel.htm"

    if (loc.indexOf(dns2) != -1)
        location.href="http://www.MontePe-Club.com/montepe-club.htm"

    if (loc.indexOf(dns3) != -1)
        location.href="http://www.Natura-Act.pt/natura.htm"
  
    if (loc.indexOf(dns4) != -1)
        location.href="http://www.Levadas-Veredas.com/levadas-veredas.htm"

    if (loc.indexOf(dns5) != -1)
        location.href="http://www.MadeiraWalks.com/levadas-veredas.htm"

    if (loc.indexOf(dns6) != -1)
        location.href="http://www.Nature-Walks.com/nature-walks.htm"
}
//-->
</script>

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Marco Ascensão

Web Developer

Portugal Portugal

Member


Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
-- There are no messages in this forum --
Permalink | Advertise | Privacy | Mobile
Web03 | 2.5.120210.1 | Last Updated 30 Oct 2001
Article Copyright 2001 by Marco Ascensão
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid