Apache HTTPS redirect from old domain to new HTTPS Domain

10,803

You need to create a separate virtual host for your old domain, which has the certificate and private key of the old domain installed. Then you can put your rewrite rule there.

Currently your virtual host will catch all domains, and therefore it presents the new domain certificate to clients connecting to the server, including ones that want to connect to old domain.

Share:
10,803

Related videos on Youtube

shabeer90
Author by

shabeer90

"It always seems impossible until it's done".- Nelson Mandela First do it, then do it right, then do it better.

Updated on September 18, 2022

Comments

  • shabeer90
    shabeer90 over 1 year

    I used to have a domain which used to have a SSL Certificate, it still does have. But I have changed the domain, and I also have a new SSL Certificate for that new domain.

    I still have users accessing the site via https://shabbasheep.myolddomain.com and it gives me the This is probably not the site that you are looking for!

    But when they access the site via shabbasheep.myolddomain.com it redirects them correctly to shabbasheep.mynewdomain.info

    Here is how my apache entries look like, got an idea to this from here

    <VirtualHost *:80>
        ServerName shabbasheep.myolddomain.com
    
        RewriteEngine On 
        RewriteCond %{HTTP_HOST} shabbasheep.myolddomain.com$
        RewriteRule ^(/(.*))?$ https://shabbasheep.mynewdomain.info$1 [L,NC,R=301]  
    </VirtualHost>
    

    My SSL

    <VirtualHost *:443>
        ServerName shabbasheep.mynewdomain.info
        ServerAlias www.mynewdomain.info
    
        RewriteEngine On 
        RewriteCond %{HTTP_HOST} shabbasheep.myolddomain.com$
        RewriteRule ^(/(.*))?$ https://shabbasheep.mynewdomain.info$1 [L,NC,R=301]  
    
        SSLEngine on
        SSLCertificateFile "mypathto.crt"
        SSLCertificateKeyFile "mypathto.pem"
        SSLCACertificateFile "mypathto.crt"
    
        ...    
        ...
        ...
    </VirtualHost>
    

    Apologies in advance if this is a duplicate question, I did have a look around, but nothing seems to work, or may be due to my lack of understanding.

    Could some one guide me on this.

    Thanks in advance.