【发布时间】:2018-08-23 18:51:07
【问题描述】:
我刚刚切换到 HTTPS。我之前将重定向设置为非 www + 没有尾部斜杠 + 没有文件扩展名。我已将重定向更改为 HTTPS。我坚持将http非www重定向到https非www。 http www 到 https 非 www 重定向工作得很好。
我从这里的答案中获得了以下代码。服务器是 Apache 2.4.33 (Unix)
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
#example.com/page will display the contents of example.com/page.html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.+)$ $1.html [L,QSA]
#301 from example.com/page.html to example.com/page
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\.html\ HTTP/
RewriteRule ^(.*)\.html$ /$1 [R=301,L]
#Force non-www:
RewriteCond %{HTTP_HOST} ^www\.mysite\.co.uk [NC]
RewriteRule ^(.*)$ https://mysite.co.uk/$1 [L,R=301]
【问题讨论】: