A “too many redirects” error happens when traffic is being redirected in such as way that a web page can never be displayed. This error is almost always the result of incorrect redirect rules. There may be other reasons though, such as the WordPress cache and web browser cookies.

Conflicting redirect rules

Redirect rules let you redirect 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 will stop following the redirects and display a “too many redirects” error.

To illustrate the point, let’s imagine you got a WordPress website with the domain example.net. You want to redirect all traffic for 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 in a web browser you will get an error. This is what Firefox will show:

A 'page isn't redirecting properly' error in Firefox.'

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, we see that 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 redirects.

The GNOME Web browser showing a 'too many redirects' error.

Image: GNOME Web showing a “too many redirects” error.

Debugging redirect errors

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:

The develop tools in Firefox showing that example.net redirects to www.example.net, and vice versa.
Image: your browser’s developer tools can help you debug redirect errors.

The screenshot shows that 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 gives us more information about the first redirect. Specifically, we 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, our .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 in the WordPress dashboard, under Settings » General. Both the WordPress URL and Site Address need to be changed to http://example.net.

The URL settings in the WordPress dashboard.

Image: the WordPress Address and Site Address clash with the redirect rule in our .htaccess file.

Using curl

Another useful tool for debugging redirection issues is the curl command line utility. For instance, you can get the same information your browser’s developer tools show when you use the -I and -L options. The first option limits the output to just the headers and the latter options 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

Cookies and cache

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 a simply 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.