.htaccess文件未重定向http:// www。到https:// www

编程入门 行业动态 更新时间:2024-10-24 06:33:45
本文介绍了.htaccess文件未重定向http:// www。到https:// www的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我制作了一个.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

本文发布于:2023-11-01 12:00:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1549274.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重定向   文件   htaccess   https   www

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!