重写httpd.conf和虚拟主机SSL的规则

时间:2022-05-28 16:57:24

I have two virtual hosts in httpd.conf one for port 443 and one for port 80:

我在httpd.conf中有两个虚拟主机,一个用于端口443,另一个用于端口80:

<VirtualHost IPADDRESS:80>
</VirtualHost>

<VirtualHost IPADDRESS:443>
</VirtualHost>

Now I want to redirect every request to my server to go to https://www.mysite.com/ except for http://www.mysite.com/blog/ I want the blog to be non SSL. Where should I put RewriteRules, in which of the virtualHost directives? And what kind of rule do I need for that?

现在我想将每个请求重定向到我的服务器,转到https://www.mysite.com/除了http://www.mysite.com/blog/我希望博客是非SSL的。我应该在哪里放置RewriteRules,在哪个virtualHost指令中?那需要什么样的规则呢?

1 个解决方案

#1


7  

In the port 80 VirtualHost, a rule will rewrite everything that isn't the blog to SSL. In the 443 host, it will rewrite blog requests to non-ssl (if you want to force them back to non-ssl)

在端口80 VirtualHost中,规则会将不是博客的所有内容重写为SSL。在443主机中,它会将博客请求重写为非ssl(如果你想强制它们回到非ssl)

<VirtualHost IPADDRESS:80>
  RewriteEngine On

  # Rewrite everything except the blog to SSL
  RewriteCond %{REQUEST_URI} !^/blog
  RewriteRule (.*) https://www.example.com/$1 [L,R,QSA]
</VirtualHost>

<VirtualHost IPADDRESS:443>
  RewriteEngine On

  # Rewrite the blog back to plain http
  # Leave this out if you don't care that https requests to the blog stay
  # on ssl
  RewriteRule ^(blog*) http://www.example.com/$1 [L,R,QSA]
</VirtualHost>

#1


7  

In the port 80 VirtualHost, a rule will rewrite everything that isn't the blog to SSL. In the 443 host, it will rewrite blog requests to non-ssl (if you want to force them back to non-ssl)

在端口80 VirtualHost中,规则会将不是博客的所有内容重写为SSL。在443主机中,它会将博客请求重写为非ssl(如果你想强制它们回到非ssl)

<VirtualHost IPADDRESS:80>
  RewriteEngine On

  # Rewrite everything except the blog to SSL
  RewriteCond %{REQUEST_URI} !^/blog
  RewriteRule (.*) https://www.example.com/$1 [L,R,QSA]
</VirtualHost>

<VirtualHost IPADDRESS:443>
  RewriteEngine On

  # Rewrite the blog back to plain http
  # Leave this out if you don't care that https requests to the blog stay
  # on ssl
  RewriteRule ^(blog*) http://www.example.com/$1 [L,R,QSA]
</VirtualHost>