重写条件(排除文件夹)不起作用

Rewrite condition (exclude folder) not working

我试图在规则中使用下划线时排除一个文件夹被重写

#replace underscores with dashes
RewriteCond %{REQUEST_URI} !^/featured_item/(.*)$ [OR]
RewriteCond %{REQUEST_URI} !\.(gif|jpe?g|png)$ [OR]
RewriteRule (.+?)_(.*) - [R=301,L]

但不知何故 /featured_item/ 被重写为 /featured-item/ anwyay

[OR] 这里的条件是一个问题,因为对于任何请求,其中一个条件将评估为真。

将您的规则更改为:

RewriteCond %{REQUEST_URI} !^/featured_item/(.*)$ [NC]
RewriteCond %{REQUEST_URI} !\.(gif|jpe?g|png)$ [NC]
RewriteRule (.+?)_(.*) - [R=301,L]

确保在清除浏览器缓存后对其进行测试。