What does this wordpress .htaccess rule do?
Solution 1:
RewriteRule ^(wp-(content|admin|includes).*) $1 [L]
I think the main intention of that directive is to prevent further processing of the file (ie. to prevent the request being forwarded to the front controller: index.php
) when requesting a URL that starts /wp-content
, /wp-admin
or /wp-includes
.
By rewriting to itself, the URL passes through unchanged and processing stops.
However, the resulting substitution is also relative, so whatever is stated as the RewriteBase
will also be prefixed to the rewritten URL. In this case the RewriteBase
is simply /
, so it is indeed rewritten to itself on the first pass (assuming this .htaccess
file is in the document root). I assume this must be intentional, otherwise they would have used a hyphen (-
) as the substitution, as in the directive above.
This "shouldn't" result in a rewrite loop, since processing should stop if the URL passes through unchanged (the rewrite is essentially "ignored").
However, to be sure it's not changed, you could simply replace $1
with -
in the RewriteRule
substitution.
If you enable full rewrite debugging, eg. LogLevel rewrite:trace6
in the server config on Apache 2.4+ you should see exactly what is happening as it should show each iteration of the rewrite.