Last active
February 10, 2023 03:09
-
-
Save iconifyit/c8d715d62b6e3960696ac1c9cbd231c5 to your computer and use it in GitHub Desktop.
A/B Testing with htaccess
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ############################### # | |
# A/B TESTING (START) # | |
# ############################### # | |
# (1) Check if our cookie is already set. | |
# If so, redirect to the previously-viewed page. | |
RewriteCond %{HTTP_COOKIE} ab_test_vers=([^;]+) | |
RewriteRule ^THE-PAGE-BEING-TESTED$ HTTP://YOUR-DOMAIN.COM/tracking/%1 [cookie=ab_test_vers_match:true:YOUR-DOMAIN.COM,L] | |
# (2) If no cookie is set (new visitor) | |
# AND the current time is on an even-numbered second | |
# Rewrite to /test-option-a AND set our cookie to `even` | |
RewriteCond %{HTTP_COOKIE} !ab_test_vers=([^;]+) | |
RewriteCond %{TIME_SEC} [02468]$ | |
RewriteRule ^test-page$ /tracking/even [cookie=ab_test_vers:even:YOUR-DOMAIN.COM,L] | |
Redirect 302 /tracking/even HTTP://YOUR-DOMAIN.COM/a/test-page | |
# (3) If no cookie is set (new visitor) | |
# AND the current time is on an odd-numbered second | |
# Rewrite to /test-option-b AND set our cookie to `odd` | |
RewriteCond %{HTTP_COOKIE} !ab_test_vers=([^;]+) | |
RewriteCond %{TIME_SEC} [13579]$ | |
RewriteRule ^test-page$ /tracking/odd [cookie=ab_test_vers:odd:YOUR-DOMAIN.COM,L] | |
Redirect 302 /tracking/odd HTTP://YOUR-DOMAIN.COM/b/test-page | |
# ############################### # | |
# A/B TESTING (END) # | |
# ############################### # |
birender
commented
Oct 18, 2019
via email
Hi,
Hope you are doing well.
Thanks for update
Birender Singh Rana
…On Wed, 17 Jul, 2019, 19:39 Scott Lewis, ***@***.***> wrote:
@birender <https://github.com/birender> I have updated the rules in the
gist to be more simple. A few things:
1. I have not tested this for entire sites. It is only meant to test a
single page. I'm not an expert on A/B testing and I don't know what the
best practices are for testing an entire site. That seems like a whole lot
of variables to try to test at once. A single page is more manageable in my
opinion but perhaps someone else (or you) knows better about this. I can
modify it to work with an entire site but not for free. Sorry but this is
how I make a living.
2. In the first step you are trying to match ^(.*)$ but I think there
is some misunderstanding. The variable %1 that is referenced in
/tracking%1 is not the page name it is the even or odd being captured
in the first RewriteCond, i.e., %{HTTP_COOKIE} ab_test_vers=([^;]+).
The ([^;]+) is capturing the variable.
3. In this rule RewriteRule (.*) https://sendeagle.com/testse/
[cookie=ab_test_vers:true:sendeagle.com,L] don't change ab_test_match
to ab_test_vers. It is not a mistake. What you did changes the value
of the variable and so breaks the cookie. ab_test_match just indicates
that we found a match. The ab_test_match value is never used though.
It is really just for debugging the rule if needed.
4. You can't do this Redirect 302 /index.html
https://sendeagle.com/index.html - it creates an endless loop.
I "think" all you need to do is:
1. Replace all instances of YOUR-DOMAIN.COM with sendeagle.com (make
sure to use https where indicated by http in the rules)
2. Replace test-page with the name of the page being tested.
3. Where you see HTTP://YOUR-DOMAIN.COM/a/test-page change this to
https://sendeagle.com/test-page-option-a
4. Where you see HTTP://YOUR-DOMAIN.COM/b/test-pagechange this to
https://sendeagle.com/test-page-option-b
5. Do not change the instances where the rules refer to tracking/odd,
tracking/even, or /tracking/%1. These are used to sort the traffic
into A or B requests.
6. You will not be able to redirect to your index.html page. It will
create an endless loop. So you will need to create a clone-home-a.html
and clone-home-b.html.
I believe the rules below should work for you if you create the
clone-home-a.html and clone-home-b.html.
`RewriteCond %{HTTP_COOKIE} ab_test_vers=([^;]+)
RewriteRule ^$ https://sendeagle.com/tracking/%1
[cookie=ab_test_vers_match:true:sendeagle.com,L]
RewriteCond %{HTTP_COOKIE} !ab_test_vers=([^;]+)
RewriteCond %{TIME_SEC} [02468]$
RewriteRule ^test-page$ /tracking/even [cookie=ab_test_vers:even:
sendeagle.com,L]
Redirect 302 /tracking/even http://sendeagle.com/clone-home-a.html
RewriteCond %{HTTP_COOKIE} !ab_test_vers=([^;]+)
RewriteCond %{TIME_SEC} [13579]$
RewriteRule ^test-page$ /tracking/odd [cookie=ab_test_vers:odd:
sendeagle.com,L]
Redirect 302 /tracking/odd http://sendeagle.com/clone-home-b.html`
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<https://gist.github.com/c8d715d62b6e3960696ac1c9cbd231c5?email_source=notifications&email_token=AAOJK33CTXQDSQ7AX6QISADP74R2TA5CNFSM4IEPKZ7KYY3PNVWWK3TUL52HS4DFVNDWS43UINXW23LFNZ2KUY3PNVWWK3TUL5UWJTQAFVOP4#gistcomment-2972926>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAOJK33P2DADOJH5IMGL3PTP74R2TANCNFSM4IEPKZ7A>
.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment