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 *:443>
    ServerName example2.com
    DocumentRoot /var/www/example2.com/public_html
    SSLEngine On

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.

  • You put both sites on https. – Michael Hampton Mar 31 '18 at 16:39
  • That's an idea. But the http site has been existed for long time, and the internal links and external links are all http links.Switching to https will damage SEO. – peter Apr 1 '18 at 1:51
  • "Switching to https will damage SEO" is a ridiculous myth. That's what 301 is for. At this point, not switching will damage SEO. – Michael Hampton Apr 2 '18 at 3:36

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.