1

I am getting the following error on the login page on our Wordpress site: There has been a critical error on your website. Please check your site admin email inbox for instructions.

After searching the internet and log files, I believe it is caused by the following error in Apache's logs: AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.

It seems to be a loop in the .htaccess file. My problem is that I do not know anything about mod_rewrite. Can anyone help me to find and remove the loop, if there is one, in my .htacccess file? Below is the file.

Thank you all.

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]

# force https
#RewriteEngine On
#RewriteCond %{HTTPS} off
#RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]**
Mike
  • 41
  • 2
  • 8

1 Answers1

0
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]

These directives can trigger a rewrite-loop (on some server configs*1) if making a request of the form /subdirectory/wp-content/foo (/subdirectory is optional) where /wp-content/foo does not exist.

The purpose of these directives is to internally rewrite requests to a WordPress subsite (in a virtual subdirectory) to the multisite core in the root of the installation and stop further processing, preventing the request being routed to the WP front-controller. *1However, on some server configs the rewrite engine is detecting a change in the URL in subsequent passes so the rewriting process never stops. If the file exists then the preceding rule would prevent further processing and no rewrite loop occurs.

Knowing more about your server config and viewing excerpts from your servers error log with mod_rewrite tracing enabled would be beneficial and potentially lead to a better solution.

Solving this problem in the context of this .htaccess file:

Although "solving" this problem means that a 404 may result instead. (Whether this is visible or not to the end user is another matter.)

Things to try... any one of the following. However, what is practical for you may depend on your file structure:

  • Remove the RewriteBase / directive. This is not required anyway in your current .htaccess file. The presence of RewriteBase results in the above rewrites being written to a URL-path, as opposed to a filesystem path. (Although I would not necessarily expect this to generate a rewrite-loop, unlike when the root-relative path is included in the substitution string itself.)

  • Change the L flag on both of these directives to END (requires Apache 2.4+). This stops all further rewrite processing. The rewrite engine does not start over and thus prevents a rewrite loop.

  • If you are already making requests of this format directly to the root and not a /subdirectory then you can change the $2 backreference in the substitution string to - (a single hyphen). This indicates no substitution and no rewrite loop occurs. (See my answer to a related question for details on this.)

  • To avoid making any changes to the existing directives you could add a couple of exceptions to the top of the file, before the existing directives:

    RewriteRule ^wp-(content|admin|includes) - [L]
    RewriteRule \.php$ - [L]
    

    This avoids any request that has been rewritten by the mentioned directives being further passed through the rewriting process.

Reference:
What does this wordpress .htaccess rule do?


RewriteRule . index.php [L]**

This looks like a markdown formatting error in your question, but those trailing ** should be removed otherwise. This would create a 500 Internal Server Error for a different reason - since it's syntactically invalid.

MrWhite
  • 12,647
  • 4
  • 29
  • 41