繁体   English   中英

如何从.htaccess / mod redirect中的URL删除一个或两个目录中的尾部斜杠?

[英]How to remove a trailing slash from one or two directories from URL in .htaccess / mod redirect?

我有以下网址:

example.com/test/
example.com/test/mode/

需要自动转换为:

example.com/test
example.com/test/mode

基本上,我希望删除斜杠。

我现有的.htaccess

RewriteEngine On

# Rule to handle example.com/xyz/mode
RewriteRule ^(\w+)/(\w+)/?$ /index.php?id=$1&mode=$2 [L,QSA]

# Rule to handle example.com/xyz
RewriteRule ^(\w+)/?$ /index.php?id=$1 [L,QSA]

在顶部添加以下规则以删除斜杠:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} \s(.+?)/+[?\s]
RewriteRule ^ %1 [R=302,L]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM