My website can be referred to as example.co.uk and example.net with optional www at the front.
I am trying to set up Apache 2.4 so that if anyone lands on anything it always permanently redirects to https://www.example.co.uk.
My current configuration mostly works in that landing on any domain via http:// forwards properly to https://www.example.co.uk however typing any https://(www.)?example.net does not redirect to https://www.example.co.uk I just get the "Security risk" ahead message and it leaves me at the .net domain. Going to https://example.co.uk does properly redirect to https://www.example.co.uk.
Can someone give me a hint as to what is going on here or if there is a better way or even a way that does what I want!
Here is my complete configuration for the virtual domain:
<VirtualHost *:80>
ServerName "www.example.co.uk:80"
ServerAlias "www.example.net"
ServerAlias "example.co.uk"
ServerAlias "example.net"
UseCanonicalName Off
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.example.co.uk$ [NC]
RewriteRule ^(.*)$ https://www.example.co.uk$1 [L,R=301]
ServerAdmin [email protected]
DocumentRoot /home/xmpl/web/www
ErrorLog /home/xmpl/logs/www/error.log
CustomLog /home/xmpl/logs/www/access.log combined
</VirtualHost>
<VirtualHost *:443>
ServerName "www.example.co.uk:443"
ServerAlias "www.example.net"
ServerAlias "example.co.uk"
ServerAlias "example.net"
UseCanonicalName Off
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.example.co.uk$ [NC]
RewriteRule ^(.*)$ https://www.example.co.uk$1 [L,R=301]
SSLEngine on
SSLVerifyClient none
SSLCertificateFile /home/xmpl/ssl/CertificateFile
SSLCACertificateFile /home/xmpl/ssl/CertificateFileCA
ProxyPass "/" "http://localhost:10300/"
ProxyPassReverse "/" "http://localhost:10300/"
ServerAdmin [email protected]
DocumentRoot /home/xmpl/web/www
ErrorLog /home/xmpl/logs/www/error.log
CustomLog /home/xmpl/logs/www/access.log combined
</VirtualHost>
Updated My SSL certificate is a SAN cert for www.example.co.uk and admin.example.co.uk. Maybe it can't redirect because of that?
SSLCertificateFile
can contain the privatekey (though it's not recommended) and almost certainly does here. OP: yes if you want to redirect from (both) https://[www.]example.net then your cert must cover both those names.SSLCertificateFile
contains the private key. If not recommended then what should I do instead? If I read your answers right then the config is fine and should work as is, I just need the .net name in the cert too?ServerName
used here and the double quotes are entirely optional.