将HTTP非www重定向到https非www

时间:2018-08-23 18:51:07

标签: .htaccess redirect

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

1 个答案:

答案 0 :(得分:0)

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

相关问题