PDA

View Full Version : Redirect based on url



noz
08-30-2005, 10:42 AM
Hi there, first of all, i'm a complete newbie to javascript and programming in general (only know html and some css).

I do however have a problem which needs to be fixed.

I have 2 domains (www.frankbakker.com) and (www.team-lockdown.com).

The problem is that team-lockdown.com redirects to frankbakker.com (it's only a domain alias). Unfortunally my hosting company can't redirect team-lockdown.com to a subdomain (lockdown.frankbakker.com).

So what i want is:
Based on the url you write in your browser (or link for that matter) to go to either frankbakker.com or team-lockdown.com. So, in case someone types www.team-lockdown.com i want them to go to lockdown.frankbakker.com and if someone types www.frankbakker.com it should just lead them to the normal page.

I have something like this in mind but i'm sure this isn't correct javascript because i'm a total newbie:

<script type="text/javascript">

function urlfoward(){
if (window.location.href = "http://www.team-lockdown.com")
{ window.location.href = "http://lockdown.frankbakker.com" }
}

</script>

Twey
08-30-2005, 10:50 AM
That's perfectly fine. You don't need the braces for the if, though, because it's only one statement.

noz
08-30-2005, 11:12 AM
That's perfectly fine. You don't need the braces for the if, though, because it's only one statement.

Hmm yes, i did it like this:

<script type="text/javascript">

function urlforward(){
if (location.href = "http://www.team-lockdown.com")
window.location.href = "http://lockdown.frankbakker.com"
}

</script>

And then:

<body onLoad="urlforward()">


This works but it also forwards to http://lockdown.frankbakker.com if the user fills in the url www.frankbakker.com in the browser. So it kinda looks like the if statement does nothing, it simply always forwards. How do i fix this?

Twey
08-30-2005, 12:04 PM
Put:
<script type="text/javascript">
if(window.location.href.indexOf("team-lockdown.com") > -1)
window.location.href = "http://lockdown.frankbakker.com/";
</script>anywhere you want on the page. This also covers permutations of the URI, like http://www.team-lockdown.com/, team-lockdown.com, www.team-lockdown.com/, &c.

noz
08-30-2005, 12:31 PM
Thx for your help, this certainly helped me out :).