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;