0

I want to set up a http website:http://example1.com, and a https website:https://example2.com using the following configuration:

Listen 80
Listen 443
NameVirtualHost *:80
NameVirtualHost *:443
<VirtualHost *:80>
    ServerName example1.com
    DocumentRoot /var/www/example1.com/public_html
</VirtualHost>

<VirtualHost *:443>
    ServerName example2.com
    DocumentRoot /var/www/example2.com/public_html
    SSLCertificateFile...
    SSLCertificateKeyFile...
    SSLEngine On
</VirtualHost>

However, if I visit https://example1.com, I am redirected to https://example2.com. If I visit http://example2.com, I am redirected to http://example1.com. I would like https://example1.com and http://example2.com do not exist at all. How should I do? I know I can add two more virtual hosts to match the other version of the websites. I can also redirect one version to the other for the sake of SEO. But that is not natural. Imagine you set up only one https site and apache only listens on port 443, search engines will never be aware of the existence of the http version of the website, which has the best SEO effects. That is exactly what I want.

peter
  • 93
  • 13

1 Answers1

0

I can also redirect one version to the other

That's exactly the correct solution here. Your Apache is now listening on both 80 and 443, and the VirtualHost matching is done within the connection, not before it. Therefore, your server must answer something, and a HTTP redirect to the canonical address would be ideal.

Esa Jokinen
  • 46,944
  • 3
  • 83
  • 129