Sometimes you see a redirect on a WordPress site and you don’t know what is causing it. Here are ways to determine the source of any redirect.
How Redirects Work?
There are only two ways a redirect can happen on the web:
- A web servers instructs the browser to redirect by using literal words — a simple
Location: ...
string in the HTTP response header which browsers immediately use to take you to another location. - A Javascript function updates the value of
window.location = ...
which causes the browser to redirect.
This guide is focused on detecting the redirects issued by the web server.
Verify X-Redirect-By Source
In 2017 Joost de Valk added the X-Redirect-By
HTTP response header to the Yoast SEO plugin and it was later included in WordPress core version 5.1.0 as a way to specify the source of the redirect.
Use the browser console to check if the redirect HTTP response includes this header to ensure the redirect was issued by WordPress and not something else:

Alternatively, use this curl command to view the headers of any GET request:
curl --silent --output /dev/null --dump-header - https://wordpress.org/a
which returns:
HTTP/2 301
server: nginx
date: Thu, 27 Mar 2025 09:22:14 GMT
content-type: text/html; charset=UTF-8
strict-transport-security: max-age=3600
x-olaf: ⛄
x-redirect-by: WordPress
location: https://wordpress.org/files/2022/10/a.png
x-frame-options: SAMEORIGIN
alt-svc: h3=":443"; ma=86400
x-nc: MISS ord 1
Note the x-redirect-by: WordPress
header in the response.
A plugin or custom PHP code could be using the native header( 'Location: ...' );
in which case it wouldn’t have the X-Redirect-By
response header.
Log WordPress Redirects
Query Monitor X-QM-… Headers
Use the Query Monitor plugin to add a stack trace of all PHP functions leading up to the redirect in a X-QM-Redirects-Redirect-Trace
header:

Note that this requires the user to be logged-in when making the requests, and have the necessary permissions to access to access the Query Monitor tooling.
Use x_redirect_by
Filter
Alternatively, you can build a custom solution that hooks into the x_redirect_by
filter which fires right before the redirect header is sent, and log the stack trace to a file:
add_filter(
'x_redirect_by',
function ( $x_redirect_by, int $status, string $location ) {
// TODO: Log the value of debug_backtrace() to a file or DB.
return $x_redirect_by;
},
100,
3
);
Here is a sample implementation as a must-use plugin that logs the redirects to a JSON file under the wp-content/uploads
directory.
Leave a Reply