使用mod重写删除尾部斜杠?

dif*_*ent 2 regex mod-rewrite

这与我之前的问题(可以在这里查看)有关.我希望能够从URL中删除尾部斜杠,以便它不会弄乱我网站的某些区域..htaccess代码在这里:

# -s = File Exists
RewriteCond %{REQUEST_FILENAME} -s [OR]
# -l = Is a SymLink
RewriteCond %{REQUEST_FILENAME} -l [OR]
# -d = Is a Directory
RewriteCond %{REQUEST_FILENAME} -d
# if we match any of the above conditions - serve the file.
RewriteRule ^.*$ - [NC,L]

# only allows '.' in the "page" portion.
RewriteRule ^([^/.]+)/?$ index.php?section=$1 [L]
RewriteRule ^([^/.]+)/([^/]+)/?$ index.php?section=$1&page=$2 [L]
RewriteRule ^([^/.]+)/([^/]+)/([^/.]+)/?$ index.php?section=$1&page=$2&split=$3 [L]
Run Code Online (Sandbox Code Playgroud)

和以前一样,我对此深表不了解,所以有人可以帮忙吗?

exh*_*uma 5

我假设你在谈论规则:

RewriteRule ^.*$ - [NC,L]
Run Code Online (Sandbox Code Playgroud)

由于另一个已经省略了尾随斜杠.

试试这个:

RewriteRule ^(.*)/$ $1 [NC,L]
Run Code Online (Sandbox Code Playgroud)

这是我在日志中看到的内容(缩写):

applying pattern '^(.*)/$' to uri 'host/'
rewrite 'host/' -> 'host'
Run Code Online (Sandbox Code Playgroud)

所以这对我来说似乎没问题.