.htaccess 将http非www重定向到https非www

.htaccess 将http非www重定向到https非www,.htaccess,redirect,.htaccess,Redirect,我刚刚切换到HTTPS。我之前设置了重定向到非www+无尾随斜杠+无文件扩展名。我已将重定向更改为HTTPS。我一直坚持将http非www重定向到https非www。http www重定向到https非www效果很好 下面的代码主要来自这里的答案。服务器是Apache2.4.33(Unix) 刚刚将该网站添加到一个免费的Cloudflare帐户,该帐户可自动将所有http重定向并重写为https。避免了头痛,问题解决了 RewriteEngine On RewriteCond %{REQUEST

我刚刚切换到HTTPS。我之前设置了重定向到非www+无尾随斜杠+无文件扩展名。我已将重定向更改为HTTPS。我一直坚持将http非www重定向到https非www。http www重定向到https非www效果很好

下面的代码主要来自这里的答案。服务器是Apache2.4.33(Unix)


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

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]