如何重定向https://开头WWW到https://和http:// WWW到https://和http://到https://
问题描述:
我需要重定向所有下列地址:如何重定向https://开头WWW到https://和http:// WWW到https://和http://到https://
http://www.example.com
https://www.example.com
http://example.com
到https://example.com
在.htaccess文件中使用永久重定向。
答
我会尝试以下方法:
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]
有几个答案这对SO。你有尝试过什么吗? – anubhava