Forums

[resolved] Need to redirect some random users (12 posts)

  1. mikeboy3
    Member
    Posted 2 years ago #

    Greetings fellow "Wordpressers",
    I have a problem, I hired a shared hosting plan and my blog outgrew it, so now, they throttled my blog's domain so that I didn't take up all the Apache's connections.

    I came up with a solution that would fix the problem, however, I don't know how to implement it.
    It turns out that since my blog is on a sub-domain, all my other sub-domains are not throttled, so, I created a clone blog that I would like to redirect the users and share the load while I get a bigger server!

    However, I tried using this code:

    <script type="text/javascript">
    <!--
    window.location = "http://avatar2.iamzaks.com/"
    //-->
    </script>

    and calling it as one of my rotating ads, (I use OpenAds) however, that does not work since I cannot add some random javascript to the banner code, and I dont want all my users to get redirected, that would generate the same issue on the clone site.

    Is there another way to automatically redirect some random users to the clone site?

    And if there isn't it, would be nice to develop one.

    Thanks in advance for your replies.

  2. adamrbrown
    Member
    Posted 2 years ago #

    Sure. Create a plugin like this:

    `
    <?php
    /*
    put a plugin name here.
    Copy the stuff in one of your other plugins
    */

    function sometimesRedirect(){

    }

  3. adamrbrown
    Member
    Posted 2 years ago #

    Oops, accidentally hit submit. Here goes again:

    <?php
    /*
    put a plugin name here.
    (Copy the format from one of your other plugins)
    */
    
    function sometimesRedirect(){
       if ( 50 < rand(0, 100) )
          header('Location: http://avatar2.iamzaks.com/');
    }
    
    add_action('init', 'sometimesRedirect')
    ?>

    As you can probably figure out, that will redirect people half the time. Make the 50 smaller if you want it less frequent.

  4. mikeboy3
    Member
    Posted 2 years ago #

    thanks for your reply mate, but, Im not good with codes, could you ellaborate a little more? like where does the url go and such.

  5. adamrbrown
    Member
    Posted 2 years ago #

    I already put your URL in there (the one from your javascript example). Just paste exactly what I wrote into a file, upload it to your plugins directory, activate it, and you're done.

    You'll need to put something where I wrote "Put a plugin name here" or else it won't show up in the plugins activation menu. Just copy the stuff from the top of another plugin and change the name.

    Done.

  6. Chris_K
    Administrator
    Posted 2 years ago #

    Sorry for the confusion: Adamrbrown's second post was temporarily held by the spam filters. I released it, but now your replies are a bit out of sync.

  7. mikeboy3
    Member
    Posted 2 years ago #

    thank you very much for your help, before the code did not show entirely, thanks a lot

  8. adamrbrown
    Member
    Posted 2 years ago #

    Ahh, I see the filters must have used "bozo" mode or whatever BBPress calls it, because I saw the post as if it had published... thus my confusion.

  9. Chris_K
    Administrator
    Posted 2 years ago #

    Similar result, but no worries, you weren't bozo'd. :-)

    This bbPress board runs Akismet. I just had to "un-spam" that particular post.

  10. adamrbrown
    Member
    Posted 2 years ago #

    Glad to hear it.

    I just noticed a small bug in that function I wrote, mikeboy. Change the function like so or you'll be hemorrhaging bandwidth:

    function sometimesRedirect(){
       if ( 50 < rand(0, 100) ){
          header('Location: yourLinkGoesHere');
          die;
       }
    }

    I left the link out this time to avoid setting off Akismet again, but you'll figure it out.

  11. mikeboy3
    Member
    Posted 2 years ago #

    ok, thanks for the code, it works great!

    however, there is a small problem that is not that urgent, the user is redirected to only one url, so if he clicks on a page or a post, when he is redirected, he is taken to the index again, and has to start over, that might be annoying (got a few emails about it already, people do love to complain) is there a way to direct them to the equivalent of where they where in the clone page?

  12. mikeboy3
    Member
    Posted 2 years ago #

    adamrbrown, since I edited the code with the corrected bug, the redirection does not work, could you please check it again.
    Thanks in advance

Topic Closed

This topic has been closed to new replies.

About this Topic