I set up WordPress as a multisite and as part of the steps, it gave some instruction to update and replace the .htaccess file.

WordPress instructed me to replace the htaccess with this:

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

# add a trailing slash to /wp-admin
RewriteRule ^wp-admin$ wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(wp-(content|admin|includes).*) $1 [L]
RewriteRule ^(.*\.php)$ $1 [L]
RewriteRule . index.php [L]

However this caused some jquery on a plugin to break.

I thought it might be useful, but could someone help provide some insight into what each of these lines does?

In particular this line:

RewriteRule ^(.*\.php)$ $1 [L]

As, if I remove this line, my plugin works fine.

Thanks in advance 🙂

2 Answers
2

I’ve been looking for details on why that line is suggested for a multisite install using subdomains as well. I actually question if both of these are relevant for a subdomain install:

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

In a sub-directory install the rules are setup slightly different to strip the sub-directory name from the request to be something like:

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

I’m seeing a redirect loop in my error logs and it’s caused by the first version of these rules since the replacement text is identical to the original text. I found some evidence that some versions of mod_rewrite will detect that the original and new text are the same and skip the re-insertion of the result. (Not sure which of the many links I’ve been reading at this point.)

I see no value in rewriting a URI to be identical to original and thus causing the link to be reinserted into the rewrite engine. With the rules removed I get the expected 404 page instead of a redirection loop that ends in a 500 server error when the redirection limit is exceeded.

Separate note, I think that the suggested sub-directory version is also broken. Because it uses ? for the sub-directory portion, it will loop on an input URL like no-such-file.php. Matching on the sub-directory portion should not allow for zero copies so the rule should likely be:

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

A similar conclusion is found here: https://wordpress.stackexchange.com/a/73185/27576

Leave a Reply

Your email address will not be published. Required fields are marked *