繁体   English   中英

将HTTP非www重定向到https非www

[英]redirect http non www to https non www

我刚刚切换到HTTPS。 之前,我将重定向设置为非www +无斜杠+无文件扩展名。 我已将重定向更改为HTTPS。 我坚持将http非www重定向到https non-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]

刚刚将网站添加到一个免费的Cloudflare帐户中,该帐户会自动将所有http重定向并重写为https。 救了头疼,问题解决了。

暂无
暂无

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

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