重定向后删除斜杠

时间:2019-07-31 20:28:37

标签: apache apache2

我正在尝试使用以下代码从http重定向到https,并在访问上下文时在结尾处给我一个“ /”。

RewriteEngine On
RewriteCond% {HTTPS}! On
RewriteRule (. *) Https: //% {HTTP_HOST}% {REQUEST_URI}

当我在上下文末尾加反斜杠的网址时,这就是问题:

http://mydomain/ip-> https://mydomain/ip /

到底是什么问题?

谢谢!

1 个答案:

答案 0 :(得分:0)

我会尝试这样做: Credits

## Turn on rewrite engine
RewriteEngine on

## Force HTTPS
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

## Remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ https://%{HTTP_HOST}%{REQUEST_URI}/$1 [L,R=301]
相关问题