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 m开发者_运维知识库ight lead to the resolution of this issue will be appreciated.
Thanks
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>
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.
I had site1 with https (certificate) and site2 with http (without certificate), both on the same IP (virtual hosts. Then I noteiced that site2 was getting incorrectly indexed by Google for https, using site1's content.
Whilst for RewriteCond listening
- for port 80, the redirect needs to sit in the .htaccess for site2,
- for port 443, the redirect needs to sit in the .htaccess for site1.
But then the discrimination no longer goes by port but by HTTP_HOST (the DNS name).
For me, site1 = shop.smartgart.com, site2 = one0.com. I put this into site1's .htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^shop.smartgart.com$
RewriteRule ^(.*)$ https://shop.smartgart.com/$1 [R=301,L]
That is: If the HTTP_HOST being handled is not site1, then redirect to site1, using the supplied suffix ($1).
Works for me!
I solved this issue with MULTIPLE redirects, not the same as @A Kunin 's answer.
Because I use different certificates for both site, and it will report certificate error if I just redirect from httpS://test1.com
to httpS://test2.com
.
My solution is: httpS://test1.com
--> http://test1.com
--> httpS://test2.com
<VirtualHost *:80>
ServerName test1.com
Redirect "/" "https://test2.com/"
</VirtualHost>
<VirtualHost *:443>
ServerName test1.com
#### The Tricky ####
Redirect "/" "http://test2.com/"
SSLEngine on
# SSLProxyEngine On
SSLCertificateFile /path/site1.crt
SSLCertificateKeyFile /path/site1.key
SSLCertificateChainFile /path/DigiCertCA1.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/site2.crt
SSLCertificateKeyFile /path/site2.key
SSLCertificateChainFile /path/DigiCertCA2.crt
SSLProtocol ALL -SSLv2 -SSLv3
SSLHonorCipherOrder on
SSLCipherSuite EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH
</VirtualHost>
精彩评论