我试图用.htaccess文件来解决我的问题。我发现用http://www.example.com访问我的页面会重定向到https://www.www.example.com。
我尝试过许多.htaccess规则,但都搞不清楚。我想将http重定向到https,非www重定向到www。
我的.htaccess文件:
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^(.*)$ [NC]
RewriteRule (.*) https://www.%1/$1 [R=301,L]我尝试了不同的规则或颠倒顺序(首先到https,然后添加www),但我仍然得到双www。
发布于 2018-11-24 19:54:02
按你要求的方式编辑。
在.htaccess中将其作为您的配置来尝试:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$
RewriteRule ^(.*)$ https://www.%1%{REQUEST_URI} [R=301,L]发布于 2018-11-24 21:00:24
好像是浏览器的问题。我使用了贾斯汀的规则,它在Safari中工作得很好,但在Chrome上,它仍然可以获得双倍的www.www。不管怎么说,它与.htaccess没有关系,因为我最初想的是,它为什么不起作用,这让我抓狂。
https://stackoverflow.com/questions/53461656
复制相似问题