使用不带“ www”之类的“ mydomain.com”之类的主域的.htaccess进行的重定向无效,将地址保留在普通的http://中,那么这段代码怎么了?以及如何强制将所有地址重定向到https://?
ErrorDocument 404 /404.php
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^www.(.*) [NC]
RewriteRule ^(.*) https://%1/$1 [R=301,L]
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1
答案 0 :(得分:1)
在不使用www和ssl的情况下,检查这些强制修改的规则
RewriteEngine On
# force to non-www
RewriteCond %{HTTP_HOST} ^www.(.*) [NC]
RewriteRule ^(.*) https://%1/$1 [R=301,L]
# force to ssl
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1 [L]
ErrorDocument 404 /404.php