如果我向服务器添加 SSL 证书,是否需要修改此 mod-rewrite 代码?
这是我去年提出的有关设置 mod-rewrites 的问题的后续:http://bit。 ly/h8PVd9
我的服务器上有以下 mod-rewrite,它强制所有流量使用完整的 URL(为了解决这个问题,我将使用 www.mysite.com )。它工作正常,没有任何问题:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.mysite\.com$ [NC]
RewriteCond %{HTTP_HOST} !^dev\.mysite\.com$ [NC]
RewriteRule ^(.*)$ http://www.mysite.com/$1 [L,R=301]
所以这一切都很好,但是我需要向服务器添加 SSL,覆盖域 www.mysite.com。我需要在现有的重写代码中添加哪些(如果有)修改/异常,以确保对 https://www.mysite 的任何调用。 com 不会被重定向到http://www.mysite.com?我需要修改任何内容吗?
This is a follow-up to a question I asked last year about setting up mod-rewrites: http://bit.ly/h8PVd9
I have the following mod-rewrite on my server which forces all traffic to use the full URL (for the sake of this question, I'll use www.mysite.com). It's working fine and there are no issues:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.mysite\.com$ [NC]
RewriteCond %{HTTP_HOST} !^dev\.mysite\.com$ [NC]
RewriteRule ^(.*)$ http://www.mysite.com/$1 [L,R=301]
So that's all well and good, however I need to add an SSL to the server, covering the domain www.mysite.com. What (if any) modification/exception do I need to add to my pre-existing rewrite code to ensure any calls to https://www.mysite.com won't be redirected to http://www.mysite.com? Do I need to revise anything at all?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不是重写专家,但我认为下面的内容会起作用。
I'm not a rewrite expert, but I think below will work.
经过测试并咨询我的虚拟主机后,这个问题的答案如下:
第一条规则处理对服务器的所有 https 请求,并允许它们通过,而不会被我的原始规则重定向。第二个是对我原来的规则的重写,解决了无论用户输入什么内容都强制使用 www.mysite.com 的问题。
@Paul - 你已经非常接近这个规则了,但是用我现有的重写规则解决方案解决了这两个问题。
After testing and consulting with my webhost, the answer to this question is the following:
The first rule addresses all https requests to the server and allows them through without getting redirected by my original rules. The second is a re-write of my original rules, and addresses the forced use of www.mysite.com regardless of what the user types in.
@Paul - you were pretty close on this one, but with my existing re-writes this solution solves both issues.