X-Redirect-By header: a standard proposal

Redirects, and in particular redirect loops, can be incredibly hard to troubleshoot. We have a solution for that, called an X-Redirect-By header. It’s a simple addition that allows us to find which piece of code is responsible for doing a particular redirect. Yoast SEO already does this and we think every other system in the world should mimic the behavior.

If you’ve ever had to diagnose larger systems, you’ll know that knowing where the redirect comes from can save you a lot of time. This is a common problem for both SEOs and web developers diagnosing weird redirect loops.

Simple standard proposal

The proposal is simple: every system that sends a redirect and/or has a method in place for sending redirects should prefix that redirect. Right before the location header, there should be an X-Redirect-By header with an identifier as its value. This identifier should clearly identify which piece of software performed the redirect.

Example of an X-Redirect-By header

When you open up https://staging-4.yoast.com/wordpress-hosting-old/ you’re redirected, by our plugin, to another page. The actual headers look like this:

HTTP/1.1 301 Moved Permanently
X-Redirect-By: Yoast SEO Premium
Location: https://staging-4.yoast.com/westhost-wordpress-hosting/

This clearly identifies Yoast SEO as the one responsible for executing that redirect. Now, if I want to change that redirect, I now know where to go and fix it.

Real world use case

Recently, we had an issue here at Yoast with a bit of code we have for redirecting UTM tags. The piece of code had its own X-Redirect-By header, and within 2 minutes, we’d found the culprit. The bug was obscure, so without that X-Redirect-By header, we would have been searching for quite a while. Searching just to figure out where in our application this redirect was being generated.

As I was discussing this header with Mark Jaquith, one of the WordPress lead developers, for inclusion in WordPress, he said:

That’s the point.

Comments? Suggestions? Implementations?

I’d love to hear your comments and suggestions and I’d love even more to see you link to implementations in systems all over the world. It’s simple standards like these that can make our life just that tiny bit easier.

Coming up next!


2 Responses to X-Redirect-By header: a standard proposal