Apache redirect multiple domain names from https
Posted
by
Cyril N.
on Server Fault
See other posts from Server Fault
or by Cyril N.
Published on 2013-10-16T08:46:08Z
Indexed on
2013/10/23
21:56 UTC
Read the original article
Hit count: 265
My server distribute two main websites, says : www.google.com & www.facebook.com (yeah I know :p)
I want them to be distributed via https. Using Apache, I defined a vhost file in sites-available/enabled containing this :
<VirtualHost *:80>
ServerName google.com
Redirect / https://www.google.com/
</VirtualHost>
<VirtualHost *:80>
ServerName facebook.com
Redirect / https://www.facebook.com/
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /srv/www/google/www/
ServerName www.google.com
ServerAlias www.facebook.com
<Directory ... />
# Google & Facebook points to the same directory (crazy right ?)
# Next of the config
</VirtualHost>
<VirtualHost *:443>
SSLEngine On
SSLCertificateFile /path/to/google.crt
SSLCertificateKeyFile /path/to/google.key
DocumentRoot "/srv/www/google/www/"
ServerName www.google.com
<Directory .../>
# Next of the config
</VirtualHost>
<VirtualHost *:443>
SSLEngine On
SSLCertificateFile /path/to/facebook.crt
SSLCertificateKeyFile /path/to/facebook.key
DocumentRoot "/srv/www/google/www/"
ServerName www.facebook.com
<Directory .../>
# Next of the config
</VirtualHost>
- If I access to https://www.google.com, the httpS works correctly
- If I access to https://www.facebook.com, the httpS works correctly.
- If I access to http://www.google.com, the http works correctly # Without https !
- If I access to http://www.facebook.com, the http works correctly # Without https !
BUT :
- If I access to https://facebook.com, it fails saying that the SSL connection is not what expected : Google.com instead of facebook.com
Based on my configuration file, I understand why, so I tried to add :
<VirtualHost *:443>
SSLEngine On
ServerName facebook.com
Redirect / https://www.facebook.com/
</VirtualHost>
But then, I can't even access facebook.com nor www.facebook.com via http/https.
So my question is quite simple : how can I redirect all https access to facebook.com (and eventually all sub facebooks : facebook.fr, www.facebook.fr, etc) to www.facebook.com (redirecting to www domain) in HTTPS ?
Thanks for your help ! :)
© Server Fault or respective owner