simple A|B - Test by .htaccess Pros, Cons & Improvements

Discuss Search Engine Optimization in relation to Joomla! 3.x. This forum will also have discussions on SEF/SEO Joomla! 3.x extensions.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10.
Post Reply
photo-deluxe
Joomla! Apprentice
Joomla! Apprentice
Posts: 5
Joined: Tue Oct 08, 2019 4:21 pm

simple A|B - Test by .htaccess Pros, Cons & Improvements

Post by photo-deluxe » Fri Nov 20, 2020 3:11 pm

Hello all,

today I had the challenge to create fast and easy a simple option for an A|B Test.
After some research I came to the conclusion that it would be easy possible by using .htaccess with cookies and rewrite conditions.

What I want to talk/discuss/improve?
  • 1. What can be improved within the htaccess-lines? (e.g. using variables)
    2. What are the pros for you?
    3. What are the cons for you?
    4. What could be an alternative simple and easy way?
Set-Up:
- google analytics is in place to track user behaviour
- standard .htaccess of joomla was used
- joomla SEF and url rewrite is active
- I created the articles and menus, with urls "www.domain.com/article" "www.domain.com/article-a" and "www.domain.com/article-b"
- I wrote the lines after #RewriteBase / and before ## Begin - Joomla! Core SEF Section
- the randomization of A and B is done by

The .htaccess code:

Code: Select all

##A/B-Testing##

#user already visited the page
RewriteCond %{REQUEST_URI} ^/article$ 
RewriteCond %{HTTP_COOKIE} currentversion=([^;])
RewriteRule ^(.*)$ https://www.mydomain.com/article-%1 [L]

#new user on page - redirect to version a
RewriteCond %{REQUEST_URI} ^/article$ 
RewriteCond %{HTTP_COOKIE} !currentversion=([^;]+)
RewriteCond %{TIME_SEC} [02468]$
RewriteRule ^(.*)$ https://www.mydomain.com/article-a [cookie=currentversion:a:mydomain.com,L]

#new user on page - redirect to version b
RewriteCond %{REQUEST_URI} ^/article$ 
RewriteCond %{HTTP_COOKIE} !currentversion=([^;]+)
RewriteCond %{TIME_SEC} [13579]$
RewriteRule ^(.*)$ https://www.mydomain.com/article-b [cookie=currentversion:b:mydomain.com,L]

##A/B-Testing- END##

Explanation:

Code: Select all

#user already visited the page
RewriteCond %{REQUEST_URI} ^/article$ 
RewriteCond %{HTTP_COOKIE} currentversion=([^;])
RewriteRule ^(.*)$ https://www.mydomain.com/article-%1 [L]
1. I checked if a user is visiting www.mydomain.com/article
2. Check if user visited the page already --> is a cookie set an available
3. If 2. is true, user will be forwarded to the page he visited (e.g. if cookie stored "a" redirect to "/article-a")

Code: Select all

#new user on page - redirect to version a
RewriteCond %{REQUEST_URI} ^/article$ 
RewriteCond %{HTTP_COOKIE} !currentversion=([^;]+)
RewriteCond %{TIME_SEC} [02468]$
RewriteRule ^(.*)$ https://www.mydomain.com/article-a [cookie=currentversion:a:mydomain.com,L]
1. Check if a user is visiting www.mydomain.com/article (reason: I want to have only one menu-link)
2. Check, that there is no cookie for visiting the site yet
3. Check, if last second of servertime is even
4. if last second is even, redirect user to version "a" -> "www.mydomain.com/article-a" and set cookie "currentversion" with value "a" for "mydomain.com"

Code: Select all

#new user on page - redirect to version b
RewriteCond %{REQUEST_URI} ^/article$ 
RewriteCond %{HTTP_COOKIE} !currentversion=([^;]+)
RewriteCond %{TIME_SEC} [13579]$
RewriteRule ^(.*)$ https://www.mydomain.com/article-b [cookie=currentversion:b:mydomain.com,L]
1. Check if a user is visiting www.mydomain.com/article (reason: I want to have only one menu-link)
2. Check, that there is no cookie for visiting the site yet
3. Check, if last second of servertime is odd
4. if last second is odd, redirect user to version "b" -> "www.mydomain.com/article-b" and set cookie "currentversion" with value "b" for "mydomain.com"

Pros:
- no additional plugin or software needed
- fast and easy solution, if you have basic .htaccess knowledge
- extendable to more versions by changing the seconds criteria (eg. 1&2,3&4,5&6 ... version "a", "b" , "c" ...)

Cons:
- existing SEO ranking may suffer (e.g. due to redirects and cananonical reasons) -> solution?
- errors in .htaccess are hard to debug without any knowledge
- if you want multiple tests, you need a lot of lines
- cookie-blockers will reduce measurements
- additional work to avoid url indexing of search engines
- it's randomized by seconds --> it's not an exact 50/50 test (but i guess it doesn't matter, if you have enough page views)

Questions:
What can be done to reduce code lines?
Easier handling of .htaccess lines to avoid errors?
What are simple alternatives?

Different idea:
A plugin where It's possible in any way to select two or multiple articles or menulinks which can be used for one url. Maybe more control due to counting option of A|B views.

I am curious what you come up with.

Best

Post Reply

Return to “Search Engine Optimization (Joomla! SEO) in Joomla! 3.x”