我制作了一个.htaccess文件,用于将所有网站流量重定向到 https:// www。。
I have made a .htaccess file to redirect all website traffic to www..
这是我完整的.htaccess文件:
RewriteEngine On RewriteCond %{HTTP_HOST} !^www\.example\ [NC] RewriteRule ^(.*)$ www.example/$1 [R=301,L]以下重定向完全按预期工作:
The below redirects work exactly as expected:
example -> www.example example -> www.example www.example -> www.example例外:
www.example -> www.example如上所示,如果您转到 http:// www。不会重定向到HTTPS版本。
As shown above, if you go to www. it doesn't redirect to the HTTPS version.
有人可以帮助我理解为什么其他重定向是工作正常,但不是吗?
Can anyone help me understand why the other redirects are working fine, but that one is not?
其他说明:我看过StackOverflow上的许多文章,但大多数解决方案都以重定向循环结尾错误。
推荐答案与123-Reg(我的托管服务提供商)联系后,他们提交了此解决方案,效果很好:
After contacting 123-Reg (my hosting provider), they submitted this solution, which works perfectly:
RewriteEngine on RewriteCond %{HTTP_HOST} ^example [NC] RewriteRule ^(.*)$ www.example/$1 [L,R=301,NC] RewriteCond %{ENV:HTTPS} !=on RewriteRule ^.*$ %{SERVER_NAME}%{REQUEST_URI} [R,L]基本上,他们已将脚本设置为执行两个任务:将域更改为 WWW ,如果尚未将其更改为 HTTPS 。此外,他们使用了 ENV:HTTPS ,这与文档中的内容( ENV:SSL )不同。
Basically they have set the script to do two tasks: Change domain to WWW, if it isn't already, THEN change to HTTPS. Also, they used ENV:HTTPS, which is different to what was found in their documentation (ENV:SSL).
很高兴能够进行这种排序,也许这可以使用123-Reg Hosting帮助其他人。
Glad to have to this sorted, and maybe this will help out others using 123-Reg Hosting.
更多推荐
.htaccess文件未重定向http:// www。到https:// www
发布评论