我想要做的是删除URL的任何结束反斜杠,除了!如果文件夹是文件夹'batman'或其任何子文件夹,例如'batman / robin',那么我想强制!反斜杠。
Example 1: www.example.com/batman -> www.example.com/batman/
Example 2: www.example.com/batman/robin -> www.example.com/batman/robin/
Example 3: www.example.com/spiderman/ -> www.example.com/spiderman
我得到了以下代码,但我无法让它工作:
RewriteEngine on
# add trailing slash when url is /batman
RewriteRule ^v$ /batman/ [R=301,L]
#remove trailing slash (ignore batman)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/batman/$ [NC]
RewriteRule ^(.+)/$ /$1 [R=301,L]
提前感谢!