从RewriteRule中排除文件夹/目录

时间:2023-02-06 10:37:01

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 hijacks 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?

当遇到特定子文件夹时,如何让mod_rewrite忽略WordPress规则以进行重写,例如opencart并使用这些子文件夹中.htaccess中定义的规则代替?

3 个解决方案

#1


20  

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 

#2


6  

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

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

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

#3


-1  

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

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

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

RewriteRule . /index.php [L,R]

</IfModule>

# END WordPress

#1


20  

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 

#2


6  

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

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

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

#3


-1  

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

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

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

RewriteRule . /index.php [L,R]

</IfModule>

# END WordPress