I've searched through a lot of different posts asking this question and I haven't really seen a straight forward answer on how to get this working.
At the moment, with the following settings, adding a www
to the front of my domain or subdomain does not load the webpage, I get a redirection saying my domain can't be found.
Could someone explain how I can get www.domain.com
and www.subdomain.domain.com
to work?
Currently, I have the following DNS records:
EDIT: This is the DNS Records that worked AFTER closetnoc's answer
I did not have the CNAME's before
A @ 1.2.3.4
A subdomain 1.2.3.4
CNAME www domain.com.
CNAME www.subdomain subdomain.domain.com.
I also have a virtual host file as follows below, (and another one for the subdomain, but you get the gist). This is to force redirect to HTTPS:
<VirtualHost *:80>
RewriteEngine on
ReWriteCond %{SERVER_PORT} !^443$
RewriteRule ^/(.*) https://%{HTTP_HOST}/$1 [NC,R,L]
</VirtualHost>
<VirtualHost *:443>
ServerName domain.com
ServerAlias www.domain.com
ServerAdmin webmaster@localhost
DocumentRoot /path/to/public_html
SSLEngine on
SSLCertificateFile /path/to/domain.crt
SSLCertificateKeyFile /path/to/domain.key
SSLCertificateChainFile /path/to/domain-bundle
<Directory "/path/to/public_html">
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/domain-error.log
CustomLog ${APACHE_LOG_DIR}/domain-access.log combined
</VirtualHost>