How do I do a redirect?

6 replies
I need my Statcounter to register the click, but need to redirect to another page.

I have used an HTML redirect I found online but it takes five seconds to redirect and displays some God awful message about redirecting. I have found some PHP, but not sure how in hell they are supposed to work and I am not sure i got everything in what i saw at #4 Schools.

If the redirect goes in the header, before the Statecounter code, will the Statecounter code get read and recorded?

Can someone please give me the code to redirect to another URL (affiliate link)? I am just lost.

I have done this before, but it has been so long i don't remember how I did it, and I can't seem to find it online.
#redirect
  • Profile picture of the author minirich
    You could use one of these
    1. HTTP Refresh Header
    First of all, you can use .htaccess to set a refresh header like this
    Code:
    Header set Refresh "3"
    This is the "static" equivalent of using the header() function in PHP
    Code:
    header("refresh: 3;");
    Note that this solution is not supported by every browser.

    2. JavaScript/jQuery

    With an alternate URL:
    Code:
    <script>
        setTimeout(function(){location.href="http://example.com/alternate_url.html"} , 3000);
    </script>
    Without an alternate URL:

    Code:
    <script>
        setTimeout("location.reload(true);",timeoutPeriod);
    </script>
    Via jQuery:

    Code:
    <script>
        window.location.reload(true);
    </script>
    3. Meta Refresh

    You can use meta refresh when dependencies on JavaScript and redirect headers are unwanted

    With an alternate URL:

    Code:
    <meta http-equiv="Refresh" content="3; url=http://example.com/alternate_url.html">
    Without an alternate URL:

    Code:
    <meta http-equiv="Refresh" content="3">
    Using <noscript>:

    Code:
    <noscript>
        <meta http-equiv="refresh" content="3" />
    </noscript>
    Optionally

    You can provide a refresh link in case something goes wrong:

    If you are not redirected automatically:
    Code:
    <a href='http://example.com/alternat_url.html'>Click here</a>
    {{ DiscussionBoard.errors[9857664].message }}
  • Profile picture of the author timpears
    Unfortunately I can't get any of this to work for me. I get stupider as i get older.

    Thanks for your help though.
    Signature

    Tim Pears

    {{ DiscussionBoard.errors[9857687].message }}
  • Profile picture of the author tks
    JavaScript can do that, if I understood your requirement
    Code:
    <a onmousedown="return rwt('yourpage.php','http://www.warriorforum.com/')" href="http://www.warriorforum.com/">Warrior Forum</a>
    Google Search result page do something like this, where rwt is a JavaScript Function
    {{ DiscussionBoard.errors[9857708].message }}
    • Profile picture of the author minirich
      This works only on a click, not automatically and instant as he wants to.

      You could use the "onload" attribute in the body tag.

      Code:
      <body onload=window.location='www.yourlocation.com'>
      The disadvantage here is, the whole page has to be finished loading (including images, scripts,...).So if your body is empty go for it.
      It will execute the counter script if it is called the same way with onload but before the redirect.
      or you could end up with something like this:
      Code:
      <body onload="callCounterScript(); window.location='www.yourlocation.com'">
      watch out for the nested quotes.

      Mike
      {{ DiscussionBoard.errors[9857753].message }}
  • Profile picture of the author tks
    Yes, OP mentioned it, he needs this to work on Clicks, "I need my Statcounter to register the click, but need to redirect to another page."
    {{ DiscussionBoard.errors[9857760].message }}
  • Profile picture of the author minirich
    Does it really count the clicks or the unique page calls?
    {{ DiscussionBoard.errors[9857792].message }}

Trending Topics