How to Fix 'Too Many Redirects' Errors in Redirection for WordPress
Content
One of the most common and frustrating issues users encounter with the Redirection plugin is the dreaded "too many redirects" error. This problem typically occurs when a redirect rule you've created inadvertently creates an infinite loop, causing your browser to get stuck. Let's break down why this happens and how to fix it.
Why Do Infinite Redirect Loops Happen?
An infinite redirect loop occurs when a rule you create matches not only the URLs you want to redirect but also the URL you are redirecting to. The most common scenario is when trying to redirect all pages on a site to the homepage.
For example, a user might create a rule with the source URL ^/(.*) and the target URL /. The expression .* matches zero or more of any character. This means it will match the homepage (/) itself, causing the following chain of events:
- A visitor requests the homepage:
yoursite.com/ - The rule matches because the path
/contains zero characters after the slash. - The plugin redirects the request to the target:
yoursite.com/(the homepage again). - The rule matches again, and the process repeats infinitely, resulting in the error.
How to Fix the Redirect Loop
The solution is to refine your regular expression so that it does not match the target URL. You need to ensure the rule only applies to pages that are not the homepage.
Solution 1: Use the + Quantifier Instead of *
A simple and effective fix is to change the quantifier in your expression. Use + (which matches one or more characters) instead of * (which matches zero or more).
- Old Rule (Causes Loop):
Source:^/(.*)
Target:/ - New Rule (Works Correctly):
Source:^/(.+)
Target:/
The new expression ^/(.+) will match any URL path that has at least one character after the slash (e.g., /about, /old-page). It will not match the homepage (/) because there is not "one or more" characters after the slash, thus preventing the loop.
Solution 2: Explicitly Exclude the Target URL
For more complex scenarios, you can write an expression that explicitly excludes your target URL or a specific pattern. This requires a more advanced understanding of regular expressions.
For instance, if you want to redirect all URLs except a specific maintenance page, your expression must avoid matching that page's path.
Best Practices and Testing
- Test Your Expressions: Before saving a new rule, always test your regular expression on a site like Regex101.com. Check that it matches the URLs you want and, crucially, does not match your target URL.
- Check the Order: If you have multiple redirects, remember that rules are processed from top to bottom. More specific rules should have a lower position number (appear higher in the list) than general catch-all rules.
- Read the Documentation: The Redirection team provides extensive documentation on using regular expressions, complete with examples and links to helpful guides.
By carefully crafting your redirect rules to avoid matching the destination, you can effectively use Redirection to manage your site's URLs without triggering errors.
Related Support Threads Support
-
Search query redirect to pagehttps://wordpress.org/support/topic/search-query-redirect-to-page/
-
How to redirect multiple URLs to one page?https://wordpress.org/support/topic/how-to-redirect-multiple-urls-to-one-page/
-
Archive redirectionhttps://wordpress.org/support/topic/archive-redirection/
-
Redirect whole site urls to single pagehttps://wordpress.org/support/topic/redirect-whole-site-urls-to-single-page/
-
Redirect all with no Permalinkhttps://wordpress.org/support/topic/redirect-all-with-no-permalink/
-
Redirection an author page with author/2 or author/3https://wordpress.org/support/topic/redirection-an-author-page-with-author-2-or-author-3/
-
Redirect pages with “+” symbolhttps://wordpress.org/support/topic/redirect-pages-with-symbol/
-
Create condition to redirecthttps://wordpress.org/support/topic/create-condition-to-redirect/
-
Redirection for Only Pages and not Postshttps://wordpress.org/support/topic/redirection-for-only-pages-and-not-posts/
-
Temporary redirect everything to a single page in the same sitehttps://wordpress.org/support/topic/temporary-redirect-everything-to-a-single-page-in-the-same-site/
-
Redirect Custom Post Typehttps://wordpress.org/support/topic/redirect-custom-post-type-2/
-
Redirect thousands of urls with parameterhttps://wordpress.org/support/topic/redirect-thousands-of-urls-with-parameter/
-
Use Site wide redirect AND specific redirects?https://wordpress.org/support/topic/use-site-wide-redirect-and-specific-redirects/
-
Provide pages of Paul to only Paul !https://wordpress.org/support/topic/provide-pages-of-paul-to-only-paul/
-
RegEx, how to redirect Everything to the homepagehttps://wordpress.org/support/topic/regex-how-to-redirect-everything-to-the-homepage/
-
Redirecting all pages to Home causes redirect loophttps://wordpress.org/support/topic/redirecting-all-pages-to-home-causes-redirect-loop/
-
Two layered redirect?https://wordpress.org/support/topic/two-layered-redirect/
-
Disable link on breadcrumbhttps://wordpress.org/support/topic/disable-link-on-breadcrumb/
-
redirect multiple urlshttps://wordpress.org/support/topic/redirect-multiple-urls-2/
-
How to redirect url with dot?https://wordpress.org/support/topic/how-to-redirect-url-with-dot/
-
Redirect posts but not archive pagehttps://wordpress.org/support/topic/redirect-posts-but-not-archive-page/
-
Redirecting Single Post Page to its Archive Pagehttps://wordpress.org/support/topic/redirecting-single-post-page-to-its-archive-page/
-
Redirect pages to homepage in multi languages sitehttps://wordpress.org/support/topic/redirect-pages-to-homepage-in-multi-languages-site/
-
redirect urls with /thumb_dir/ urlshttps://wordpress.org/support/topic/redirect-urls-with-thumb_dir-urls/
-
URLs ending with the same valuehttps://wordpress.org/support/topic/urls-ending-with-the-same-value/
-
Redirect formulahttps://wordpress.org/support/topic/redirect-formula/
-
Redirect Helphttps://wordpress.org/support/topic/redirect-help-8/
-
Redirect to main page onlyhttps://wordpress.org/support/topic/redirect-to-main-page-only/
-
how to create a redirect pagehttps://wordpress.org/support/topic/how-to-create-a-redirect-page-2/
-
Help me, pleasehttps://wordpress.org/support/topic/help-me-please-66/
-
i get ERR_TOO_MANY_REDIRECTShttps://wordpress.org/support/topic/i-get-err_too_many_redirects/
-
How to redirect all pages of a site to the landing page?https://wordpress.org/support/topic/how-to-redirect-all-pages-of-a-site-to-the-landing-page/