If I type in example.com
into the URL it redirects to https://www.example.com
which is great, same with typing http://example.com
I get the correct redirect to https://www.example.com
.
However if I type in https://example.com
it takes me to the warning SSL Certificate invalid page. After checking what the domain the certificate was for I realised that it's taking me to completely different website I have on the server(the same site that comes up if I type my VPS IP Address directly into the URL.)
Heres my config file:
<VirtualHost *:80>
ServerName example.com
Redirect permanent / https://www.example.com/
</VirtualHost>
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName www.example.com
ServerAlias *.example.com
ServerAdmin noreply@example.com
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /static /home/user/example/static
<Directory /home/user/example/static>
Require all granted
</Directory>
<Directory /home/user/example/example>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIScriptAlias / /home/user/example/example/wsgi.py
WSGIDaemonProcess exsite python-path=/home/user/example python-home=/home/user/example/venv
WSGIProcessGroup exsite
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^ https://www.example.com%{REQUEST_URI} [R=301,L]
SSLCertificateFile /etc/letsencrypt/live/www.example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/www.example.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>