I have the following three rewrite rules in my /usr/local/etc/apache22/extra/httpd-vhosts.conf file:
Both rule 1 and rule 2 work fine. Rule 3 acts like it is being completely ignored. I added the following to my site's main index.shtml page:
and I correctly see "example.com on" (without the quotes) when I browse to https://example.com. But the rewrite rule, which should be triggered by those two matches, does not fire. Rearranging things so that rule 3 is first doesn't help, either.
Code:
# Rule 1 - rewrite any example.com to www.example.com
rewriteCond %{HTTP_HOST} ^example\.com
rewriteRule (.*) http://www.example.com$1 [R=301,L]
# Rule 2 - likewise for an IP literal.
rewriteCond %{HTTP_HOST} ^10\.20\.30\.40
rewriteRule (.*) http://www.example.com$1 [R=301,L]
# Rule 3 - As rule 1, but for https
# For some reason, this does not work.
rewriteCond {HTTPS} =on
rewriteCond %{HTTP_HOST} ^example\.com
rewriteRule (.*) https://www.example.com$1 [R=301,L]
Code:
<!--#echo var="HTTP_HOST" -->
<!--#echo var="HTTPS" -->