我的 .htaccess 文件中的规则如何例外?

How can I have an exception for a rule in my .htaccess file?

可能是个非常简单的问题,但我做不出来。

案例: 通过以下 htaccess 行将从 URL 中删除尾部斜杠:

RewriteCond %{request_method} ^GET$
RewriteCond %{REQUEST_URI} ^(.+)/$
RewriteRule ^(.+)$ %1 [L,R=301] # <- this line removes the trailing slash
RewriteRule .* index.php [L]

如何为该页面创建例外: mydomain.com/paypal/ipn/ 所以它不会做 301 重定向到:mydomain.com/paypal/ipn

您可以使用 RewriteCond 创建例外:

RewriteCond %{request_method} ^GET$
RewriteCond %{REQUEST_URI} !^/paypal/ipn/ [NC]
RewriteRule ^(.+?)/$ %1 [L,R=301,NE]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]