我需要重定向以下所有地址:
http://www.example.com
https://www.example.com
http://example.com
到https://example.com
使用.htaccess文件中的永久重定向。
答案 0 :(得分:1)
我会尝试以下方法:
RewriteEngine On
# URL with www rewrite to https without www
RewriteCond %{HTTP_HOST} ^(www\.)(.*) [NC]
RewriteRule (.*) https://%2%{REQUEST_URI} [L,R=301]
# URL without www rewrite to https
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^(www\.)(.*) [NC]
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]