我想将所有网站URL从http重定向到https。我的网站是使用简单的php建立的。我不使用任何开源框架或CMS。我使用下面的代码来做到这一点。
我尝试了以下方法。
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
我还尝试了以下网址提供的解决方案,对我不起作用
htaccess redirect to https://www
RewriteEngine On
RewriteCond %{HTTPS} off
# First rewrite to HTTPS:
# Don't put www. here. If it is already there it will be included, if not
# the subsequent rule will catch it.
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Now, rewrite any request to the wrong domain to use www.
# [NC] is a case-insensitive match
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
它会引发以下错误:
页面无响应。重定向次数过多。