Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A/B Testing with apache and mod_rewrite

Tried searching for this but my google-fu is lacking today.

So I have 2 versions of site, in

/var/www/vhosts/testa.mydomain.com/httpdocs and 
/var/www/vhosts/testb.mydomain.com/httpdocs

where each documentroot is pretty much a complete site overhaul, and I want to do A/B (multivariate) testing to see which site performs better.

Googling last week I saw suggestions on doing this time based (even & odd seconds), but because the site is a basket site (or perhaps even a basket-case!), I don't want to flit between 2 different processing scenarios mid-transaction.

So I thought it would be good to serve from testa if client ip address last octet was even, and from testb if last octet was odd. We could then at least gain some metrics on how many people abandoned the basket as too unwieldy in different versions of the site.

I'm pretty sure that a bunch of RewriteCond lines based on %{REMOTE_ADDR} will do it, but I'm pretty hopless at mod_rewrite.

users would visit test.mydomain.com, and be should served from one or the other DocumentRoot's evenly, not seeing testa or testb in their url, but we could log each variant's performance.

Any kindly guru's able to advise ?

TIA David

Update: I can set up testa.mydomain and testb.mydomain as subdomains via virtual hosts if that would help any.

like image 379
David Shields Avatar asked Jul 22 '11 15:07

David Shields


People also ask

What is mod_rewrite in Apache?

The mod_rewrite module uses a rule-based rewriting engine, based on a PCRE regular-expression parser, to rewrite requested URLs on the fly. By default, mod_rewrite maps a URL to a filesystem path. However, it can also be used to redirect one URL to another URL, or to invoke an internal proxy fetch.

What is RewriteCond and RewriteRule?

There are two main directive of this module: RewriteCond & RewriteRule . RewriteRule is used to rewrite the url as the name signifies if all the conditions defined in RewriteCond are matching. One or more RewriteCond can precede a RewriteRule directive.


2 Answers

Option 1 (Redirects) add one of these to both domains

Place on even number site (testb.mydomain.com)

RewriteEngine On
RewriteCond %{REMOTE_ADDR} [13579]$
RewriteRule .* http://testa.mydomain.com/$1 [R=301,L]

Place on odd number site (testa.mydomain.com)

RewriteEngine On
RewriteCond %{REMOTE_ADDR} [02468]$
RewriteRule .* http://testb.mydomain.com/$1 [R=301,L]

Option 2 (subfolders NOT subdomains)

RewriteEngine On
#direct to EVEN SITE
RewriteCond %{REMOTE_ADDR} [02468]$
RewriteRule (.*) /testa.mydomain.com/$1 [L]

#direct to ODD SITE
RewriteCond %{REMOTE_ADDR} [13579]$
RewriteRule (.*) /testb.mydomain.com/$1 [L]
like image 167
Andrew Winter Avatar answered Sep 22 '22 13:09

Andrew Winter


Google now offers A/B/N testing through its Google Analytics Experiments Interface / API.

The article about this is written at: https://blog.crazyegg.com/2015/06/02/ab-testing-google-analytics/

You can read more about it from Google at: https://developers.google.com/analytics/solutions/experiments

So, one possibility would be to put Google's tracking in both versions of your site and let Google handle redirects of your site (you can make redirects be equal at all times or take Multi-Armed bandits approach).

like image 37
Jenna Kwon Avatar answered Sep 22 '22 13:09

Jenna Kwon