强制用户通过 www 访问该网站。和 https
我正在尝试编写一个附加 www 的 .htaccess 规则。到域,如果需要的话到http,但我似乎找不到适用于每种情况的规则或一组规则。
这些案例是...
\https://www.site.com - 应该可以工作
\http://www.site.com - 应转至 \https://www.site.com
\http://site.com - 应该转到 \https://www.site.com
\https://site.com - - 应该转到 \https://www.site.com
任何帮助将不胜感激。
I am trying to write an .htaccess rule that appends www. to the domain and s to http if required but I can't seem to find a rule or set of rules that works for each case.
The cases are...
\https://www.site.com - should just work
\http://www.site.com - should go to \https://www.site.com
\http://site.com - should go to \https://www.site.com
\https://site.com - - should go to \https://www.site.com
Any help would greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试此规则:
这应该涵盖请求不是 HTTPS(第一个条件)或主机不以
www.
开头(第二个条件)的两种情况。在这种情况下,第三个条件将获取没有起始www.
(如果存在)的主机,然后在规则的替换中使用该主机。Try this rule:
This should cover both cases in which either the request was not HTTPS (first condition) or the host does not start with
www.
(second condition). In that case the third condition will grab the host without the startingwww.
(if present) that is then used in the rule’s substitution.