需要 htaccess 代码来重写带有尾部斜杠的 URL,XML 文件除外

Need htaccess code to rewrite URLs with trailing slash except XML files

在 .htaccess 中加入以下代码,将 WordPress 中的 URL 从没有尾部斜杠重写为有一个。例如,www.domain.com/post -> www.domain.com/post/.

问题是,它为 sitemap.xml 做这件事会破坏它。如何排除 .xml 个文件?

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://domain.com// [QSA,L,R=301]

只需插入另一个 RewriteCond,不包括以 .xml 结尾的 URL

RewriteCond %{REQUEST_URI} !\.xml$