简体   繁体   English

我是否需要修改这个mod重写代码,如果我添加SSL证书到我的服务器?

[英]Do I need to modify this mod-rewrite code if I add an SSL certificate to my server?

This is a follow-up to a question I asked last year about setting up mod-rewrites: http://bit.ly/h8PVd9 这是我去年提出的有关设置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 ). 我的服务器上有以下mod-rewrite,它强制所有流量使用完整的URL( 出于这个问题,我将使用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 . 所以,这一切都很好,但我需要一个SSL添加到服务器,覆盖域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 ? 什么(如果有的话)修改/例外,我需要添加到我的预先存在的重写代码,以确保到https任何来电://www.mysite.com不会被重定向到http://www.mysite.com? Do I need to revise anything at all? 我是否需要修改任何内容?

I'm not a rewrite expert, but I think below will work. 我不是重写专家,但是我认为下面的方法可以工作。

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www\.mysite\.com$ [NC]
RewriteCond %{HTTP_HOST} !^dev\.mysite\.com$ [NC]
RewriteRule ^(.*)$ http://www.mysite.com/$1 [L,R=301]

After testing and consulting with my webhost, the answer to this question is the following: 经过我的虚拟主机的测试和咨询之后,此问题的答案如下:

RewriteCond %{HTTPS_HOST} ^mysite.com [NC]
RewriteRule ^(.*)$ https://mysite.com/$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^mysite.com [NC]
RewriteRule ^(.*)$ http://www.mysite.com/$1 [R=301,L]

The first rule addresses all https requests to the server and allows them through without getting redirected by my original rules. 第一条规则将所有https请求处理到服务器,并允许它们通过而无需被我的原始规则重定向。 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. 第二个是重写我的原始规则,并解决了无论用户输入什么内容而强制使用www.mysite.com的问题。

@Paul - you were pretty close on this one, but with my existing re-writes this solution solves both issues. @Paul-您在这一点上非常接近,但是通过我现有的重​​写,此解决方案可以解决这两个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM