Rewrite rule for httpd.conf and SSL virtual host

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 each request to my server to go to https://www.mysite.com/ , with the exception of http://www.mysite.com/blog/ . I want the blog not to be SSL. Where should I put RewriteRules, in which virtualHost directive? And what rule do I need for this?

+4
source share
1 answer

In port 80 of VirtualHost, the rule will rewrite everything that is not a blog for SSL. On host 443, it overwrites blog requests in non-ssl (if you want to force them back into 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> 
+7
source

Source: https://habr.com/ru/post/1411204/


All Articles