Last updated: 2 March 2022
A “too many redirects” error happens when website traffic is redirected in such a way that a page can never be displayed. This error is almost always the result of conflicting redirect rules. There may be other reasons though, such as the WordPress cache and web browser cookies.
Redirect rules let you redirect website traffic. For instance, you can have a rule that redirects traffic from http://example.com to https://example.com. And normally, these rules work fine. But, what if there is another rule that redirects traffic from https://example.com to http://example.com? The result is an indefinite loop. When a browser detects such a loop it stops following the redirects and displays the “too many redirects” error.
To illustrate the point, let’s imagine you have a WordPress website for example.net. You want to redirect all traffic to www.example.net to example.net (which is good SEO practice) and you therefore add a redirect rule to the site’s .htaccess file:
# BEGIN WordPress RewriteEngine On RewriteBase / RewriteRule ^index.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] # END WordPress # Redirect to non-WWW RewriteCond %{HTTP_HOST} ^www. [NC] RewriteCond %{HTTP_HOST} ^(?:www.)?(.+)$ [NC] RewriteRule ^ http://%1%{REQUEST_URI} [L,NE,R=301]
The rule itself is correct, and there are no conflicting rules in the .htaccess file. However, when you view the site you suddenly get an error. This is what Firefox might show:
Image: Firefox showing a “too many redirects” error.
Firefox suggests that the issue may be related to cookies (specifically, refusing to accept cookies). A quick way to check if that’s the case is by opening the page in another web browser. Here, GNOME Web throws the same error, and it has some useful debugging information: the browser gave up on the page after it had followed 20 redirections.
Image: GNOME Web showing a “too many redirects” error.
To fix a redirection error you need to find out exactly how traffic is redirected. There a various tools you can use to check this. For instance, you can use your browser’s developer tools. If you select the Network tab in Firefox or Chrome and refresh the page you can see all the redirects:
Image: your browser’s developer tools can help you debug redirect errors.
The image shows there is an indefinite loop between example.net and www.example.net. We can also see that the browser gave up after 20 redirects.
The header information in the side pane provides more information about the first redirect. Specifically, you can see that the location of the redirect is http://www.example.net/. And, right below that line we got the culprit: X-Redirect-By: WordPress
. In other words, the .htaccess file is redirecting from www.example.net to example.net, but WordPress is doing the reverse.
The WordPress redirect is typically the website URL. You can check (and change) the URL via the WordPress dashboard, under Settings » General. In this case, both the WordPress URL and Site Address need to be changed to http://example.net.
Image: the WordPress Address and Site Address clash with the redirect rule in the .htaccess file.
If the WordPress URL is looking correct then it is worth checking the wp-config.php file as well. The WordPress URL can be overridden in the file using the WP_HOME
and WP_SITEURL
variables.
Another useful tool for debugging redirection errors is the curl
command line utility. For instance, you can get the same information your browser’s developer tools show using the -I
and -L
options. The first option limits the output to just the headers and the latter option follows any redirects:
$ curl -IL example.net HTTP/1.1 301 Moved Permanently Connection: Keep-Alive Content-Type: text/html; charset=UTF-8 X-Redirect-By: WordPress Location: http://www.example.net/ Date: Fri, 06 Mar 2020 10:35:25 GMT HTTP/1.1 301 Moved Permanently Connection: Keep-Alive Date: Fri, 06 Mar 2020 10:35:25 GMT Location: http://example.net/ HTTP/1.1 301 Moved Permanently Connection: Keep-Alive Content-Type: text/html; charset=UTF-8 X-Redirect-By: WordPress Location: http://www.example.net/ Date: Fri, 06 Mar 2020 10:35:25 GMT HTTP/1.1 301 Moved Permanently Connection: Keep-Alive Date: Fri, 06 Mar 2020 10:35:25 GMT Location: http://example.net/ ... curl: (47) Maximum (50) redirects followed
There are few other things you can try if there don’t appear to be any conflicting redirect rules. If you are using a WordPress caching plugin then you can try clearing the cache. Of course, that won’t work if you can no longer get to the WordPress dashboard (unless you use a tool such as WP-CLI). You may need to delete cached files on the file system – we are happy to help with that.
You can also try opening the page in a private / incognito browser window. This is an easy way to bypass your browser’s cache. Another option is to open the page in another browser – ideally one you don’t normally use.
And finally, it is also worth checking your browser’s cookie settings. If you have configured your browser to refuse cookies then that may well be your issue. The opposite can also be a solution: you can try clearing cookies for the domain you are trying to access.