You have probably heard of both terms before, AB Testing and SEO Rating. AB testing is the act of serving a portion of your users a different experience than the other users to test which experience is the best. 300

Your SEO Rating is the rating Search engines give your website. SEO is short for Search Engine Optimization. Websites at the top of your google search result have either a higher SEO rating than the results below it, or it is a paid ad. There are a lot of things you can do to improve your SEO, I have a separate article that talks about some things you can do. This website (which you are probably reading from right now) is not SEO optimized in the slightest, which is because I have a lot of non-existing article references like this “article” about myself that currently leads to a 404.

In this article I’ll explain how AB testing can negatively impact your SEO, and how it can be avoided. I will explain with the use of php examples.

AB and SEO

How not to

There are a lot of ways to do this wrong

Bad Example 1

<?php
// A simple user ID
$userId = $_COOKIE['user_id'] ?? rand(1, 100);
setcookie('user_id', $userId, time() + 3600, '/');
if ($userId % 2 === 0) {
    // Redirect users to variant B
    header("HTTP/1.1 301 Moved Permanently");
    header("Location: /variant-b.php");
    exit;
}
?>
 
<!DOCTYPE html>
<html>
...

This does look like a good attempt, but there is an issue .

  • 301 redirect. The header("HTTP/1.1 301 Moved Permanently"); tells google that the original page is gone forever. Which is not what you want.