Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache HTTPS to HTTPS Redirection

We have a client server hosting our web application using Apache 2.2 & Tomcat 6 in RHEL. I have setup apache re-write rule for http to https redirection and it works fine. We have two DNS names that are used to access the same application. Test1.com and Test2.com. I want all the users trying to access http:// test1.com or https:// test1.com to https:// test2.com. As mentioned, http:// test1.com to https:// test2.com redirection is working fine. I am not able to implement https://test1.com to https://test2.com.

I have tried Virtual Hosts, ServerAlias, NameVirtualHost, but nothing works. Any suggestions if we can handles this via re-write would help. Any other pointers that might lead to the resolution of this issue will be appreciated.

Thanks

like image 548
Noman Amir Avatar asked May 04 '11 12:05

Noman Amir


People also ask

How do I automatically redirect HTTP to HTTPS on Apache server?

In Apache, the preferred way to redirect HTTP to HTTPS is to configure the 301 redirect in the domain's virtual host.

Is redirect HTTP to HTTPS secure?

Here's how it all boils down: HTTPS is secure, while HTTP is not. The websites that have made the move to redirect HTTP to HTTPS appear with a padlock on the browser bar before the URL.


2 Answers

Try the following:

 RewriteEngine On 

 RewriteCond %{HTTP_HOST} test1.com$
 RewriteRule ^(.*)$ https://test2.com$1 [L,NC,R=301]

If you have a <VirualHost> for both :80 and :443, this redirect should go in both configurations.

like image 184
clmarquart Avatar answered Sep 17 '22 01:09

clmarquart


I solved this issue with redirect, but I had to setup virtual host for https redirect with all necessary ssl settings.

<VirtualHost *:80>
    ServerName test1.com
    Redirect "/" "https://test2.com/"
</VirtualHost>

<VirtualHost *:443>
    ServerName test1.com
    Redirect "/" "https://test2.com/"
    SSLEngine on
    # SSLProxyEngine On
    SSLCertificateFile /path/site.crt
    SSLCertificateKeyFile /path/site.key
    SSLCertificateChainFile /path/DigiCertCA.crt
    SSLProtocol ALL -SSLv2 -SSLv3
    SSLHonorCipherOrder on
    SSLCipherSuite EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH
</VirtualHost>

<VirtualHost *:443>
    ServerName test2.com
    ...
    SSLEngine on
    # SSLProxyEngine On
    SSLCertificateFile /path/site.crt
    SSLCertificateKeyFile /path/site.key
    SSLCertificateChainFile /path/DigiCertCA.crt
    SSLProtocol ALL -SSLv2 -SSLv3
    SSLHonorCipherOrder on
    SSLCipherSuite EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH
</VirtualHost>
like image 28
A Kunin Avatar answered Sep 17 '22 01:09

A Kunin