I’m trying to redirect traffic, and I’ve managed to make it work on HTTP with this:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^wiki\.example\.com
RewriteCond %{HTTPS} !=on
RewriteRule (.*) http://example.com/wiki/$1 [L]
RewriteCond %{HTTP_HOST} ^db\.example\.com
RewriteCond %{HTTPS} !=on
RewriteRule (.*) http://example.com/db/$1 [L]
So far I haven’t gotten it to work with HTTPS. Anyone got any ideas?
You need to duplicate the code for
HTTPSbut set theRewriteCondto%{HTTPS} =onfor the SSL redirect. I would also set theRewriteBaseoption as well as setting theR=301flag on the redirect. Further you can simplify things a bit by using a back reference to theRewriteCondby using%Nfor wiki/db –If your domain name might change in the future and you want to make sure you are redirecting based on the match, you can also use more back references in your
RewriteCond–