我刚刚设置了我的域以使用ssl并将此代码添加到.htaccess文件(在root):
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(.*\.)*mysite.com$ [NC]
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)$ https://www.mysite.com/$1 [R]
它重定向来自mysite.com的所有流量,但来自WWW.mysite.com的流量显示为不受信任。 我试过在mysite.com之前添加www:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(.*\.)*www.mysite.com$ [NC]
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)$ https://www.mysite.com/$1 [R]
但它不起作用。知道此代码的人可以帮助..
更新:https://mysite.com/工作正常,但mysite.com(没有https://)尝试重定向到https://www.mysite.com/并提出“不受信任的证书消息,此证书仅对mysite有效.COM /” (显而易见?)注意:mysite.com实际上不是我的网站,我已将其替换为我的网站名称,因为我还不能透露我自己网站的地址。
答案 0 :(得分:2)
如果我正确理解您的问题,您需要将所有匹配重定向到https://mysite.com/而不是https://www.mysite.com/。
如果是这种情况,请在上次重写规则中遇到问题 - 将其编辑为
RewriteRule ^(.*)$ https://mysite.com/$1 [R]
答案 1 :(得分:1)
此代码会将所有流量从HTTP重定向到您的网站
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}