I have two sites hosted on one machine: foo.com and blank.test, I want each of them to redirect HTTP traffic to the corresponding HTTPS site. When I navigate to one, I get redirected to the other.
foo.com.conf:
<VirtualHost _default_:443>
ServerName foo.com
ServerAlias foo.com
# ... etc
</VirtualHost>
<VirtualHost _default_:80>
ServerName foo.com
ServerAlias foo.com
Redirect permanent / https://foo.com
</VirtualHost>
blank.test.conf:
<VirtualHost _default_:443>
ServerName blank.test
ServerAlias blank.test
# ... etc
</VirtualHost>
<VirtualHost _default_:80>
ServerName blank.test
ServerAlias blank.test
Redirect permanent / https://blank.test
</VirtualHost>
At the moment
- https://foo.com works
- http://foo.com redirects to https://blank.test
- http://blank.site experiences permissions errors, but that's probably irrelevant
- http://blank.site redirects to https://blank.test
Why is http://foo.com redirecting to https://blank.test?
I think this is because named virtual hosts work off the header and with SSL enabled, Apache won't see the header until after SSL negotiation. So what I think is happening is that at redirect, you are going to whichever domain has precedence (meaning the order it loaded).
You could try this, which should (tm) force it to the right domain:
However, you can't have more than 1 SSL site per IP without using SNI. See, for example, http://www.tutorialspoint.com/articles/how-to-set-up-multiple-ssl-host-with-a-single-apache-server