Flux RSS des billets

DotMG's joblog

Work hard at whatever you do! (Ecc. 9. 10a)
mod_rewrite proxy, simple but not well known.
Publié le 8 Oct 2013, 6:42 am dans apache

I recently purchased a wildcard SSL for my domain *.dot.mg. I have many subdomains that I wanted also to serve as https.

Once the SSL installed and fully functional, accessing to any of the subdomains leaded to the main site, because SSL configuration is per IP address, and not per domain name. But the solution is very simple, and in 3 lines. It is done by proxying requests to the main site to the non-https version. So, visitor connectes via https to https://blog.dot.mg/, but this request is directed to my main site https://dot.mg/. It will be the responsibility of https://dot.mg/ to redirect internally this request into http://blog.dot.mg/

It is important to know the difference between normal redirection and proxy redirection. With normal redirection, when a visitor goes to https://blog.dot.mg/, he is asked to go to http://blog.dot.mg instead, so he will load the unsecure version of the site. On the other hand, with proxy redirection, it is the webserver who will load the unsecure version of the site, then change all references to http into https and give the modified html page to the visitor. Thus, the communication between the client and the server is secure

 RewriteCond %{HTTP_HOST} ^blog.dot.mg$
 RewriteCond %{HTTPS} =on
 RewriteRule ^(.*)$ http://blog.dot.mg/$1 [P,L]

As simple as that.

The first lines filters the rewriting rule only for the subdomain blog.dot.mg. The second applies only the rule for HTTPS. The third line does the proxy redirection. Note the flag P instead of R. It is the only trick that makes it possible to view the site through https.

Les commentaires sont fermés pour ce billet.