正在从htaccess重定向中删除尾部斜杠



我想使用htaccess进行重定向,但遇到了尾部斜杠的问题。

我想从重定向https://test.com/transferhttps://test.com/transfer/https://test2.com/destination下面是我的htaccess规则,但它似乎只适用于https://test.com/transfer但不https://test.com/transfer/

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI}  ^/transfer$ [NC]
RewriteRule ^ https://somesite.com/destination/$1 [R,L]

我的规则出了什么问题?

尝试:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI}  ^/transfer/?$ [NC]
RewriteRule ^ https://somesite.com/destination/$1 [R,L]

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/transfer/?$ https://somesite.com/destination/ [NC,R,L]

请确保只使用RewriteEngine On一次。

如果您想重定向transfer内的所有内容:如果transfer是一个目录btw,请使用:

RewriteEngine on
RewriteRule ^/transfer/?(.+)?$ https://somesite.com/destination/$1 [R, L]

最新更新