4

I have two virtual hosts in httpd.conf one for port 443 and one for port 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?

Tamik Soziev
  • 14,307
  • 5
  • 43
  • 55

1 Answers1

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)

<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>
Michael Berkowski
  • 267,341
  • 46
  • 444
  • 390
  • In your 443 config, `RewriteRule ^(/blog/.*) http://www.example.com$1 [L,R,QSA]` may be simpler. But that's nitpicking – nikoshr May 08 '12 at 07:36