将http非www重定向到https非www

问题描述 投票:0回答:1

我刚刚切换到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]
.htaccess redirect
1个回答
0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.