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.