This is a great piece of code to rotate 2 separate landing page urls using PHP location headers and a 50% random string. This code also preserves the URL string so that any url string variables are sent to the rotated links of the outbound pages.

We achieve this by using a simple redirect script php header.

This snippet of code is excellent for the testing of different landing page offers with different designs and elements, so you may determine which page layout and design performs better.

First, I set up an index.php page in a directory on my site. In this case is was just a simple /r directory. So the file structure would look something like this

and the php code would be added to the index.php file in this /r directory.

if (mt_rand(0,1) == 0) {
header("Location:". $_SERVER['QUERY_STRING']);
} else {
header("Location:". $_SERVER['QUERY_STRING']);

Using this code, and with it preserving your url string, your traffic link would look something like:

and with the script above installed on the index.php of the /r directory, the random string in the php snippet will send your traffic to each link approximately 50% of the time, evening out the traffic sent to the 2 pages you are testing. Ultimately, you will see your traffic sent to each page and those links will now look something like this:


I hope this helps you out as much as it’s helped me out.

It’s a very quick and easy way to test 2 separate landing pages with different landing page elements to test what page converts better based on your page variables.