将http非www重定向到https非www

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了将http非www重定向到https非www相关的知识,希望对你有一定的参考价值。

我刚刚切换到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]
答案

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

以上是关于将http非www重定向到https非www的主要内容,如果未能解决你的问题,请参考以下文章

Htaccess 301将规则/ HTTP重定向到HTTPS /非www到www

通过 htaccess 将所有 http 和 https 非 www URL 重定向到 https://www.xyz.com

https 非 www 重定向

htaccess 重定向非 www http 和 https

使用www从非www http重定向到https

将 https 非 www 重定向到 https www 不工作的虚拟主机