How Do I Rotate Urls To The Main Url

16 replies
I'm trying to rotate 10 different urls to one url. For example, when people go to www.Example.com, how can I make it direct them www.Example.com/1, www.example.com/2, www.example.com/3, and so on. I want the urls to rotate to a different page every time the page is loaded.

Is there an easy way to do this?

Thanks in advance,
#main #rotate #url #urls
  • Profile picture of the author Marc Quarles
    Do you want the redirect to be random, or do you want to track it (ie, 2 comes after 1, 3 comes after 2, etc)?
    {{ DiscussionBoard.errors[2960701].message }}
  • Profile picture of the author kkoechel
    the only way I know do it would be to literally track what page is loaded to a db token, and increment the token each time you get someone requesting the page.

    it's not really hard, but it's not easy on the db if you have a ton of people at once, and I cannot figure out why you would want to "load balance" 10 different pages either.

    do you mind if I ask you why you want to do this as opposed to a literally randomizer function in php.

    if you used a rand function in php you only need to use a meta refresh
    {{ DiscussionBoard.errors[2960738].message }}
    • Profile picture of the author mlmguru
      I'm not really sure what your are saying, I don't have any programming experience. But this is what I'm trying to do, I set up an advertising co-op, with 10 other people, so I'm trying to create 10 landing pages for each person, all with a separate url for that person. And I'd like to set it up so when someone visits the main url, it directs the visitor to a different landing page each time, I hope I am making sense.

      Here is a php code I was trying, am I way off?

      <?php $link[1] = "http://yourdomain.com/index1.html";
      $link[2] = "http://yourdomain.com/index2.html";
      $link[3] = "http://yourdomain.com/index3.html";
      if(!sset($HTTP_cookie_VARS['link'])){ $n=count($link);
      $rand=rand(1,$n); setcookie("link",$rand,time()+3600);
      header('location:'.$link[$rand]); }else{ $go=$link[$_COOKIE['link']]; header('location:'.$go); } ?>
      {{ DiscussionBoard.errors[2960771].message }}
  • Profile picture of the author kkoechel
    that is close to what I was suggesting above. Convince the people that randomizing is the same as incrementing or "making sure" everyone gets a 1/10 ratio... they would get the same with a rand(1-10) function too.

    To keep track of the token you should be on and display you still need some centralized way to store it, ie a database, like a mysql one. Does your hosting having DB hosting too?
    {{ DiscussionBoard.errors[2960867].message }}
  • Profile picture of the author Krishna876
    I've never tried it but I read this article recently about rotating urls.

    It's a free plugin that may be what you're looking for...

    URL Rotator Plugin for Wordpress | Ad.Ventures in Internet Marketing
    {{ DiscussionBoard.errors[2960924].message }}
    • Profile picture of the author Marc Quarles
      Ok, shoot me a PM with details if you still need this done. I can get it set up for you in a few minutes. No charge - just being a helpful neighbor.

      Marc
      {{ DiscussionBoard.errors[2961321].message }}
      • Profile picture of the author Fundermentalist
        [DELETED]
        {{ DiscussionBoard.errors[2967769].message }}
        • Profile picture of the author Brandon Tanner
          Alright, I was bored, so I wrote a simple script that will do this without requiring a database, or cookies, or anything like that. Basically, it just uses a flat file (plain text file) to store a number that increments between 1-10 each time someone visits your landing page, then serves the destination page based on the incremented number.

          First, upload the attached ad_number.txt file to the directory where your landing page will be.

          Then just copy and paste the following php code into your landing page (don't forget to change wherever it says YourWebsite.com/pageX.html to reflect each of your 10 different destination pages, and of course make sure your landing page file name ends with a .php extension)...

          <?php

          // Get number from ad_number.txt

          $file = fopen('ad_number.txt', 'r');
          $current_number = fgets($file);
          fclose($file);

          // Increment number

          if ($current_number < 10)
          {$new_number = $current_number + 1;
          } elseif ($current_number == 10)
          {$new_number = 1;}

          // Write incremented number to file

          $file = fopen('ad_number.txt', 'w') or die("can't open file");
          fwrite($file, $new_number);
          fclose($file);

          // Serve webpage associated with current number

          if ($current_number == "1")
          {header("Location: http://www.YourWebsite.com/page1.html");
          } elseif ($current_number == "2")
          {header("Location: http://www.YourWebsite.com/page2.html");
          } elseif ($current_number == "3")
          {header("Location: http://www.YourWebsite.com/page3.html");
          } elseif ($current_number == "4")
          {header("Location: http://www.YourWebsite.com/page4.html");
          } elseif ($current_number == "5")
          {header("Location: http://www.YourWebsite.com/page5.html");
          } elseif ($current_number == "6")
          {header("Location: http://www.YourWebsite.com/page6.html");
          } elseif ($current_number == "7")
          {header("Location: http://www.YourWebsite.com/page7.html");
          } elseif ($current_number == "8")
          {header("Location: http://www.YourWebsite.com/page8.html");
          } elseif ($current_number == "9")
          {header("Location: http://www.YourWebsite.com/page9.html");
          } elseif ($current_number == "10")
          {header("Location: http://www.YourWebsite.com/page10.html");
          }

          ?>


          Hope it helps!
          Signature

          {{ DiscussionBoard.errors[2968668].message }}
          • Profile picture of the author TomCPAWAY
            <?
            $links = array(
            "http://yoursite.com/1",
            "http://yoursite.com/2",
            "http://yoursite.com/3"
            );

            shuffle($links); // shuffles the array
            shuffle($links); // shuffles the array again
            shuffle($links); // shuffles the array and again

            $rand_key = array_rand($links, 1);// (this grabs 1 random key value from the array)

            $url = $links[$rand_key]; // this forums the url;

            header("Location: $url"); // this redirects to the random url
            exit();

            ?>



            The above is another simple way to do it, this requires no database, text file, or even dealing with permission simply copy and paste the code into a .php file and you're golden.
            Signature


            Don't Get Porked, Bring Home the Bacon with CPAWay. Proudly Accepting Warriors Every Day! New Affiliate? No problem!
            www.cpaway.com
            {{ DiscussionBoard.errors[2969416].message }}
            • Profile picture of the author deepakg
              Originally Posted by TomCPAWAY View Post

              <?
              = array(
              "http://yoursite.com/1",
              "http://yoursite.com/2",
              "http://yoursite.com/3"
              );

              shuffle(); // shuffles the array
              shuffle(); // shuffles the array again
              shuffle(); // shuffles the array and again

              = array_rand(, 1);// (this grabs 1 random key value from the array)

              = ; // this forums the url;

              header("Location: "); // this redirects to the random url
              exit();

              ?>



              The above is another simple way to do it, this requires no database, text file, or even dealing with permission simply copy and paste the code into a .php file and you're golden.
              I check this script and it is not working properly..
              {{ DiscussionBoard.errors[2970960].message }}
            • Profile picture of the author Bruce Wedding
              Originally Posted by TomCPAWAY View Post

              <?
              = array(
              "http://yoursite.com/1",
              "http://yoursite.com/2",
              "http://yoursite.com/3"
              );

              shuffle(); // shuffles the array
              shuffle(); // shuffles the array again
              shuffle(); // shuffles the array and again

              = array_rand(, 1);// (this grabs 1 random key value from the array)

              = ; // this forums the url;

              header("Location: "); // this redirects to the random url
              exit();

              ?>



              The above is another simple way to do it, this requires no database, text file, or even dealing with permission simply copy and paste the code into a .php file and you're golden.
              Wow! You don't trust the php shuffle and rand functions do you? Why not this?

              <?
              $links = array(
              "http://yoursite.com/1",
              "http://yoursite.com/2",
              "http://yoursite.com/3"
              );

              $rand_key = array_rand($links);// (this grabs 1 random key value from the array)
              $url = $links[$rand_key];
              header("Location: $url"); // this redirects to the random url
              exit();

              ?>
              {{ DiscussionBoard.errors[6451629].message }}
          • Profile picture of the author Steven Fullman
            Here's the same thing in 4 lines...(sorry I was bored too)

            <?php

            // Get number from ad_number.txt

            $current_number = file_get_contents('ad_number.txt');

            // Increment number

            $current_number = ($current_number < 10 ? ++$current_number : 1);

            // Write incremented number to file

            file_put_contents('ad_number.txt', $current_number);

            // Serve webpage associated with current number

            header("Location: http://www.YourWebsite.com/page$current_number.html");

            ?>


            Cheers,
            Steve
            Signature

            Not promoting right now

            {{ DiscussionBoard.errors[5596897].message }}
  • Profile picture of the author kkoechel
    he wants it to rotate in a demonstrable evenly manner
    {{ DiscussionBoard.errors[2969884].message }}

Trending Topics