Problems with Wordpress’ mod_rewrite rules when re

2019-08-12 06:37发布

问题:

please take a look at my .htaccess:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

For Wordpress it works fine.

But I have a problem: I have a directory called lo, used for links exchange, has nothing to do with the Wordpress blog. Now, I can't access my lo directory, it redirects me to a wordpress post. Why?

回答1:

Does /lo/'s DirectoryIndex point to /lo/index.php?

If so, and assuming your answer to Pekka's question is "Yes", the problem likely originates from the fourth RewriteRule. A request to /lo/ maps to /lo/index.php, which matches

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

...and gets rewritten to index.php in your site root, which is the WordPress file. I'm not sure what the point of this rule is (it does block access to WordPress .php files, but in kind of a super-general way), so I don't know what the best recommendation is for conditioning it, but the following would work:

RewriteCond %{REQUEST_URI} !^/lo
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]