In Apache 2.4.6, I would like to redirect requests from http://A.org/foo
and https://A.org/foo
to https://B.org/foo
.
I am using the following directives:
<VirtualHost 1.2.3.4:80>
ServerName B.org
ServerAlias A.org
RewriteEngine on
RewriteCond %{HTTP_HOST} !^B.org$
RewriteRule ^/(.*)$ https://B.org/$1 [R=permanent,L]
</VirtualHost>
<VirtualHost 1.2.3.4:443>
ServerName B.org
ServerAlias A.org
RewriteEngine on
RewriteCond %{SERVER_PORT} ^443(s)
RewriteCond %{HTTP_HOST} !^B.org$
RewriteRule ^/(.*)$ https://B.org/$1 [R=permanent,L]
</VirtualHost>
When I visit http://A.org/foo
, this redirects to https://B.org/foo
(correct).
When I visit https://A.org/foo
, this loads https://B.org/foo
but does not rewrite the URL. So I get an SSL certificate domain mismatch error from the web browser.
Is there something wrong with the second VirtualHost
directive which would keep the URL from being rewritten?