Results 1 to 5 of 5

Thread: Redirect based on url

  1. #1
    Join Date
    Aug 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Redirect based on url

    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>

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    That's perfectly fine. You don't need the braces for the if, though, because it's only one statement.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Aug 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Twey
    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?

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Put:
    Code:
    <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.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Aug 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thx for your help, this certainly helped me out .

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •