Using apache 2.4 and my site is on www.example.com, which automatically gets redirected to https://www.example.com, wherein it is fully accessible and functional.
However, when I explicitly try using http://example.com or https://example.com, I get greeted by a placeholder page.
What I would like to happen is to redirect non-www to www. Ex (https://example.com -> https://www.example.com
I have set up a rewrite rule in my .conf file, but for some reason, it's not working. All I'm seeing is a placeholder page when accessing non www.
<VirtualHost <ip>:80>
ServerName www.example.com
ServerAlias example.com
# Redirect to www
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
Redirect permanent / https://www.example.com/
</VirtualHost>
<VirtualHost <ip>:443>
ServerName www.example.com
ServerAlias example.com
SSLCertificateFile /home/admin/certs/www_example_com.crt
SSLCertificateKeyFile /home/admin/certs/www_example_com.key
SSLCACertificateFile /home/admin/certs/DigiCertCA.crt
SSLEngine on
SSLProtocol +TLSv1.2 -TLSv1.1 -TLSv1 -SSLv3 -SSLv2
DirectoryIndex index.php index.html index.htm
# redirect to www
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]