How to stop website redirection

Infinite forwarding

If a browser notices that it is being redirected endlessly from one URL to the next, it cancels after a certain number of redirects with an error message, e.g. Firefox:

Error: redirect error

The accessed website redirects the request in such a way that it can never be completed.

This problem can sometimes occur when cookies are disabled or refused.

... and Google Chrome:

This page doesn't work
example.com redirected you too many times.
Delete your cookies.
ERR_TOO_MANY_REDIRECTS

Both browsers indicate a cause of the error in their error messages: websites that redirect to themselves until a cookie is set. Browsers in which cookies are deactivated end up in an endless redirect.

In addition, there are incorrect redirects, such as the following redirect directive in the .htaccess file:

This results in an endless redirect https://example.com/foo -> https://example.com/foo/bar -> https://example.com/foo/bar/bar -> ...

It would be better to forward it here with mod_rewrite:

The $ delimiter ensures that no characters can follow “/ foo” in the path, so that https://example.com/foo/bar is no longer forwarded.

In another example, static URLs are generated using mod_rewrite, e.g. example.com/foo is internally rewritten to example.com/index.php?bar=foo:

In addition, conversely, visitors and search engines should be redirected from the old dynamic URLs to the new static URLs:

Both together now ensure endless forwarding.

This can be solved by first installing the 301 forwarding and giving it an L (ast) flag, which prevents the following rules from being executed in the event of a match. However, the forwarding is wrongly activated in a second pass if the query string bar = foo is appended in a first pass through the internal redirection. This can be prevented by an additional check on the request, which is not changed by other rules:

Since browsers load old 301 redirects from their cache, the browser cache may also have to be cleared so that the infinite redirect is fixed (see also this blog post)