If a URL redirects to the wrong page or your browser shows a “too many redirects” error, something on your website may be causing an unexpected redirect.
The source could be WordPress, a plugin, a theme, or your web server configuration. You can often find out what causes a redirect by opening the affected URL and checking the X-Redirect-By HTTP response header in your browser's developer tools.
If the header identifies WordPress or a plugin, you can use a backtrace snippet to find the function or plugin responsible for the redirect. If the header is missing, inspect your .htaccess file, NGINX configuration, and CDN settings for redirect rules.
What Is a Redirect Loop (ERR_TOO_MANY_REDIRECTS)?
Identifying a redirect loop is usually straightforward, but determining why it occurs can be more difficult. A typical symptom is that the page never fully loads because the browser keeps redirecting the request instead of displaying the site content.
Different browsers may display redirect-loop errors in different ways. They generally report that too many redirects were detected and that the page cannot be loaded.
Chrome, for example, displays the error code ERR_TOO_MANY_REDIRECTS. Firefox may display "The page isn't redirecting properly," while Safari may show "Safari Can't Open the Page".
Common Causes of Unwanted Redirects in WordPress
Cached 301 Redirects
Browsers can cache permanent (301) redirects and continue redirecting a URL even after you remove the original redirect.
To rule out browser caching, test the affected URL in a private window or clear the browser cache before investigating other potential causes.
Mismatched WordPress Address and Site Address
If the site URLs under Settings → General use http:// or a different hostname than the one your server redirects to, WordPress and the server may redirect requests back and forth, causing a redirect loop.
To fix the issue, make both URL fields in WordPress match the address you use on your website. If the fields are locked, check whether WP_HOME or WP_SITEURL is defined in the wp-config.php file.
If you enforce redirects through .htaccess or another server configuration, make sure the destination URL uses the correct protocol (https://) and hostname (www or non-www).
HTTPS Behind a Proxy or CDN
A load balancer or CDN can cause a redirect loop if it sends HTTP requests to WordPress, which then redirects them to HTTPS. If the proxy continues to forward requests over HTTP, the cycle repeats.
On Cloudflare, this often occurs when SSL/TLS encryption is set to Flexible. To resolve the issue, try switching to Full (strict).
If you use a different proxy server, you can add the following code workaround to wp-config.php to ensure WordPress detects the original request as HTTPS:
WordPress Core, Plugins and Themes
WordPress can automatically redirect some URLs. For example, if you change a post or page slug, WordPress may redirect visitors from the old URL to the new one instead of showing a 404 error.
To check whether a WordPress canonical redirect is causing the problem, you can temporarily disable it with this line of code:
Another possible cause is a redirect rule added by a different plugin or theme. Popular examples include Redirection and Rank Math, both of which support custom redirect rules and auto-redirects.
Other plugins and themes may also use redirects for specific purposes. For example, they may redirect visitors after they submit a form or attempt to log in.
If you suspect that a plugin or theme is causing an unexpected redirect, follow the steps below to identify its source.
Server Configuration
Server configuration can be another source of unexpected redirects. If you cannot identify or resolve the issue elsewhere, check your NGINX configuration or the .htaccess file if your site runs on Apache.
On Apache, you can usually find .htaccess in the main directory where your WordPress files are stored. If you have configured redirects directly in NGINX, check the server configuration for rules that may conflict with other URLs or rewrite rules.
Server configuration files can contain hundreds of lines, so reviewing them manually may take some time. AI can help you scan the configuration for potentially invalid, duplicate, or conflicting redirect rules.
How to Find What Is Causing the Redirect
Step 1: Follow the Redirect Chain
When a visitor opens a page on your WordPress site, their browser first sends a request to the server. The server then returns a response containing HTTP headers.
These headers can reveal the redirect status and may contain an X-Redirect-By header added by WordPress or a plugin. You can inspect the response directly using your browser's developer tools. Online tools such as HTTP Status Code Checker or Redirect Checker can be useful as well.
Here is how to inspect the HTTP headers using your browser:
Chrome
- Open DevTools with
F12(orCmd+Option+Ion Mac). - Click the Network tab.
- Reload the page, then click the relevant request in the list.
- Look at the Headers inside the right sidebar.
Firefox
- Open DevTools with
F12(orCmd+Option+Ion Mac). - Go to the Network tab.
- Reload the page, then click the relevant request in the list.
- The Headers section should appear in the right sidebar.
Step 2: Check the X-Redirect-By Header
When you are trying to track down a redirect issue, check for the X-Redirect-By HTTP header. WordPress adds this header when a redirect is performed using the wp_redirect() function.
If the header is missing, the redirect may be occurring at the server level, such as in .htaccess or nginx.conf, before PHP or WordPress code is executed. However, the absence of this header does not by itself prove that the redirect originates from the server, as a plugin or custom code can also perform redirects without adding the header.
The X-Redirect-By header can indicate that a redirect was generated by WordPress, a plugin, or a theme. By default, WordPress uses WordPress as the header value. Some plugins, such as Yoast SEO or Permalink Manager, may replace the default value with their own name.
For example, a response might include:
HTTP/1.1 301 Moved Permanently
Location: https://example.com/new-page/
X-Redirect-By: WordPress
Step 3: Trace the Redirect With a PHP Backtrace
The X-Redirect-By response header indicates that WordPress issued a redirect, but it does not identify the component that initiated it. To trace the redirect's origin, you can intercept the redirect and output a PHP backtrace showing the call stack that led to wp_redirect().
The snippet below works with redirects triggered by wp_redirect() and wp_safe_redirect(). It can help you find out whether the redirect comes from WordPress core, a plugin, or your theme.
It does not detect redirects configured in .htaccess, NGINX, or a CDN. If the browser still redirects but no debug page appears, the redirect likely occurs outside WordPress.
When you are logged in as an administrator, any front-end URL that would trigger a redirect displays a debug page instead. This does not affect logged-out visitors or redirects in the WordPress admin dashboard.
The debug page shows the destination URL, HTTP status code, and function calls involved in the redirect, along with the plugin or theme each call belongs to.
Step 4: Disable Plugins One by One
Redirect loops can happen when two WordPress plugins interfere with each other. One plugin might redirect visitors to a URL, while another sends them back to the original URL.
To identify the plugin causing the conflict, you can also deactivate your plugins one at a time and test the affected URL after each change. This process can take time if your site uses many plugins, so other troubleshooting methods may be more practical.
Frequently Asked Questions
Why Does WordPress Redirect to the Homepage?
A redirect plugin, an SEO plugin such as 404 to 301, or a server-level rule may redirect all 404 URLs to the homepage.
This is generally not recommended. Google’s Martin Splitt advises against redirecting 404s to the homepage and recommends redirecting to a relevant replacement page or keeping the 404.
Can I Hide the X-Redirect-By Header?
Yes. To hide the X-Redirect-By header, add the following line of code:
This prevents WordPress from setting the header on redirects.







Leave a Reply