April 24, 2012

How to run two versions of static website simultaneously for A/B testing?

Question by Jitendra Vyas

For example I have a very simple website only HTML/CSS/Javascript based no php,.net, ruby is being used. Some visitors to my site should see version “A,” while others see version “B.

Site is hosted on Apache server

Answer by Starx

One way is by analyzing the IP Address or range.

Create list of IP Address/Range

$ips = array(
    "a" => array( 'xxx.xxx.xxx.xxx', ....),
    "b" => array( 'xxx.xxx.xxx.xxx', ....),
);

Now, use $_SERVER['REMOTE_ADDR'] and switch the domain

if(in_array($ips['a'], $_SERVER['REMOTE_ADDR'])) {
    header("location: website.com/a");
} else {
    header("location: website.com/b");
}
exit;

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!