In case you have moved to a new host.. A javascript code to redirect your users

Discussion in 'JavaScript' started by AddaxSoft, Jan 22, 2009.

  1. #1
    Hi there,

    This scirpt is not for only redirecting. that can be done with HTML only.

    let's say you have a forum in host 'X' ..

    your links are:
    http://x/showthreads.php?=23124324
    PHP:
    so when you move to a new host 'Y' you want your users to be redirected to the same threads but on the new host!
    http://y/showthreads.php?=23124324
    PHP:
    you first have to create a 404 page for the X host and include this script in it.
    
    <script type="text/javascript">
    /*
    Coded by AddaxSoft webiste: www.addaxsoft.com
    */
    var url = window.location.href;
    url = url.substring(url.lastIndexOf('/') + 1);
    document.write('<strong>We have moved to the new server... you\'re being redirected to it now....</strong>');
    setTimeout("location.href = 'http://Y/' + url",2000);
    </script> 
    PHP:
    don't forget to change 'Y' to your new host

    Save it as 404.html .. and use it in your old host files :)


    you're done =)
     
    AddaxSoft, Jan 22, 2009 IP
  2. phper

    phper Active Member

    Messages:
    247
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #2
    I would throw a http redirect header on the server side instead so that search engine crawlers know that the page has been moved and where to.
     
    phper, Jan 22, 2009 IP
  3. MMJ

    MMJ Guest

    Messages:
    460
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hate to be negative but this isn't a good technique.... at all.
     
    MMJ, Jan 24, 2009 IP
  4. rohan_shenoy

    rohan_shenoy Active Member

    Messages:
    441
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    60
    #4
    ^Well, it just a means of advertising his website!
     
    rohan_shenoy, Jan 24, 2009 IP
  5. yoavmatchulsky

    yoavmatchulsky Member

    Messages:
    57
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    48
    #5
    this redirection can be done at a much lower level, saving resources and time.
    you can use .htaccess redirections on the server, or in a server-side script by modifying the headers.

    Most of the users don't care if you're on server X or Y, as long as they get their page. I dont think a message that the server has changed and waiting two seconds is best practice.
    its better to issue a 301/302 header message and save the users time waiting for the "redirection page" you created.

    its also better for SEO, as phper said, because then [favorite-searchengine-here] updates all the links to your old page to point to the new one, giving it more juice.
     
    yoavmatchulsky, Jan 24, 2009 IP
  6. AddaxSoft

    AddaxSoft Guest

    Messages:
    44
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    that's so untrue, I respect what you said but please don't attack me by saying such things :)

    ~regards,
     
    AddaxSoft, Jan 25, 2009 IP
  7. AddaxSoft

    AddaxSoft Guest

    Messages:
    44
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Thank you for your addition, I didn't know that I can do that with .htaccess
     
    AddaxSoft, Jan 25, 2009 IP