.htaccess http://www.www.example.com 重定向到https://www.example.com

.htaccess http://www.www.example.com 重定向到https://www.example.com,.htaccess,redirect,.htaccess,Redirect,我有一个我想运行的网站https://www.example.com,我在htaccess文件上设置了规则,并在那里编写了以下规则 RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301] RewriteCond %{HTTP:X-Forwarded-Proto} !https RewriteCond %{HTTPS} off RewriteRule

我有一个我想运行的网站
https://www.example.com
,我在htaccess文件上设置了规则,并在那里编写了以下规则

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTPS} off
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
在这些规则之后,我的网站在谷歌上显示为
www.example.com
,当我点击
www.example.com
时,它会重定向我
www.www.example.com

表示在url中添加了两倍的www。我在看是否有人能在这方面帮助我。谢谢

由于您的第二条规则在
www.%{HTTP\u HOST}
前加前缀,您将获得双倍
www

您可以将规则设置为:

RewriteEngine On

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]

RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]

确保使用新浏览器测试此更改。

谢谢,它可以正常工作。我只需要确定我是否使用了。是否应该重定向到
https://example.com/
已被重定向到
https://www.example.com/
使用问题/答案中的第一条规则。如果成功了。