wordpress 从 RewriteRule 中排除文件夹/目录

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15295366/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 19:11:25  来源:igfitidea点击:

Exclude a folder/directory from RewriteRule

wordpress.htaccessmod-rewrite

提问by OC2PS

I have a pretty standard WordPress .htaccess with the following URL rewrites

我有一个非常标准的 WordPress .htaccess,其中包含以下 URL 重写

# BEGIN WordPress 
<IfModule mod_rewrite.c>  
RewriteEngine On  
RewriteBase /  
RewriteRule ^index\.php$ - [L]  
RewriteCond %{REQUEST_FILENAME} !-f  
RewriteCond %{REQUEST_FILENAME} !-d  
RewriteRule . /index.php [L]  
</IfModule> 
# END WordPress  

WordPress is installed in my domain root. I have some other scripts in subfolders, e.g. /opencart These subfolders contain their own .htaccess files.

WordPress 安装在我的域根目录中。我在子文件夹中有一些其他脚本,例如 /opencart 这些子文件夹包含它们自己的 .htaccess 文件。

Unfortunately, it seems that WordPress hiHymans the rewrites for some of these scripts sometimes.

不幸的是,WordPress 似乎有时会劫持其中一些脚本的重写。

How can I ask mod_rewrite to ignore WordPress rules for rewrites when encountered with specific subfolders e.g. opencart and to use the rules defined in the .htaccess within these subfolders instead?

当遇到特定子文件夹(例如 opencart)时,如何要求 mod_rewrite 忽略 WordPress 重写规则,并改用这些子文件夹中 .htaccess 中定义的规则?

回答by Felipe Alameda A

You may try replacing the complete WP rule-set with this one:

您可以尝试用这个替换完整的 WP 规则集:

# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]

# Include in the next line all folders to exclude
RewriteCond %{REQUEST_URI}  !(folder1|folder2|folder3) [NC]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress 

回答by France Amookomoro

In the .htaccess file in your site root, add the following ABOVE the WordPress .htaccess directives:

在站点根目录的 .htaccess 文件中,在 WordPress .htaccess 指令上方添加以下内容:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/subdirectoryname1/(.*)$ [OR]
RewriteCond %{REQUEST_URI} ^/subdirectoryname2/(.*)$ [OR]
RewriteRule ^.*$ - [L]
</IfModule>

回答by Bang Andre

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]

RewriteRule ^/(folder1)/(.*) /folder1/ [R]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . /index.php [L,R]

</IfModule>

# END WordPress