Problems with Wordpress’ mod_rewrite rules when requesting existing files

六眼飞鱼酱① 提交于 2019-12-13 18:25:19

问题


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]


来源:https://stackoverflow.com/questions/3434610/problems-with-wordpress-mod-rewrite-rules-when-requesting-existing-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!