Redirect HTTP domain A to HTTPS domain B (with lets encrypt cert installed already)

June 22, 2017 165 views
Apache Let's Encrypt Ubuntu 16.04 Ubuntu

I would like to redirect domain A that is not secure (http) to domain B that is secure (https) that has a let's encrypt ssl cert already installed. I believe the answer to my question is to utilize the rewrite rules. But, the documentation is a little difficult to understand -for me. Any help, with examples would be awesome.

2 comments
1 Answer
hansen June 22, 2017
Accepted Answer

Hi @michel92df116ca8bc0546fb67

You can use the following method to redirect by changing your VirtualHost:

<VirtualHost *:80>
  ServerName domainA.com
  Alias www.domainA.com
  Redirect / https://www.domainB.com/
</VirtualHost>

And the restart Apache with sudo apachectl restart
If everything works, then change it to Redirect permanent / https://www.domainB.com/

  • In the case of nginx, you would use

    server {
        listen 80;
        server_name domainA.com;
        return 302 https://domainB.com/;
    }
    

    Change to 301 for a permanent redirect.

    If you wish to include everything that might have followed the domain:

    server {
        listen 80;
        server_name domainA.com;
        return 301 https://domainB.com$request_uri;
    }
    
Have another answer? Share your knowledge.