[英]Redirect to https://www.example.com
Currently I'm using http://example.com but I want redirect all to http s :// www .example.com 目前我正在使用http://example.com,但我希望将所有内容重定向到http s :// www .example.com
I read several topics here and tried quite a few solutions to this but nothing worked for me. 我在这里阅读了几个主题并尝试了很多解决方案,但对我没有任何帮助。
My last try was this: 我的最后一次尝试是:
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
When I'm using this code I can see this: enter image description here 当我使用此代码时,我可以看到: 在此输入图像描述
But it gives me this message also: 但它也给了我这个信息:
The page isn't redirecting properly. 页面未正确重定向。 Firefox has detected that the server is redirecting the request for this address in a way that will never complete. Firefox检测到服务器正在以永远不会完成的方式重定向此地址的请求。
Can you help me with this? 你能帮帮我吗?
Replace example with your domain and try 用您的域替换示例并尝试
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
Looks to me that you're also trying to force www. 在我看来你也试图强迫www。 You can do both by using this in your .htaccess
: 你可以在你的.htaccess
使用它来做到这.htaccess
:
RewriteCond %{HTTP_HOST} !^www\. [NC,OR]
RewriteCond %{HTTPS} !=on
RewriteRule ^.*$ https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
Place this rule to the top of your .htaccess
file and make sure you clear your cache before you test it. 将此规则放在.htaccess
文件的顶部,并确保在测试之前清除缓存。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.