我想使用htaccess进行重定向,但遇到了尾部斜杠的问题。
我想从重定向https://test.com/transfer或https://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]