Installed SSL on Virtualhost. But Unless HTTPS Protocal Specified, User Redirected to Wrong Site
I installed SSL on a Virtualhost previously running on port 80. The port is now running on port 443 as it should. When I enter the URL along with the HTTPS protocal into the address bar, everything works fine. But if I omit HTTPS, it redirects to another one of my virtualhosts.
I know it's a problem with the using port 443 and that Apache is rather choosing a virtualhost with port 80. Is my only option to alter the .htaccess file, or there a better way to address the issue?
Here's a pseudo mockup of my current setup under sites-enabled
<virtualhost *:443="">SSLEngine On
SSLCertificateFile /path/to/cert
SSLCertificateKeyFile /path/to/keyfile
SSLCACertificateFile /path/to/CAcert
# Admin email, Server Name (domain name), and any aliases
ServerAdmin mysite@test.com
ServerName www.mysite@test.com
ServerAlias mysite@test.com
# Index file and Document Root (where the public files are located)
DirectoryIndex na.html na.php
DocumentRoot /path/to/mysite@test.com/root</virtualhost>
4 Replies
<virtualhost *:80="">ServerName www.mysite@test.com
ServerAlias mysite@test.com
Redirect permanent / https://www.mysite@test.com/</virtualhost>
I'm assuming I place your example code in the same .conf file as my port 443 virtualhost. Is the below code correct?
<virtualhost *:80="">ServerName www.mysite@test.com
ServerAlias mysite@test.com
Redirect permanent / https://www.mysite@test.com/</virtualhost>
<virtualhost *:443="">SSLEngine On
SSLCertificateFile /path/to/cert
SSLCertificateKeyFile /path/to/keyfile
SSLCACertificateFile /path/to/CAcert
# Admin email, Server Name (domain name), and any aliases
ServerAdmin mysite@test.com
ServerName www.mysite@test.com
ServerAlias mysite@test.com
# Index file and Document Root (where the public files are located)
DirectoryIndex na.html na.php
DocumentRoot /path/to/mysite@test.com/root</virtualhost>