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         @      
A         subdomain
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 *: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

    ErrorLog ${APACHE_LOG_DIR}/domain-error.log
    CustomLog ${APACHE_LOG_DIR}/domain-access.log combined

1 Answer 1


Your DNS example is missing a few elements. Here is how I would set things up.

example.com A
www CNAME example.com
sub-domain CNAME example.com
www.sub-domain CNAME example.com

If all are on a single web server, then the web server will take the request header and respond to the request accordingly.

In this case, only your parent domain needs an IP address. Remember, this is routing domain names to IP addresses only. As for the rest, CNAME is an alias that points to your domain name. So for www.example.com, sub-domain.example.com, and www.sub-domain.example.com, these will all use the IP address of example.com.

You will need a similar site set up for sub-domain.example.com and www.sub-domain.example.com as you do for example.com and www.example.com. Remember that sub-domains are separate sites from the parent and need to be set-up as a new site. If you want the sub-domain content to be served out of your parent domain, then that is a whole other question, but still requires the sub-domain site to be created.

  • Thank you! For those who are wondering, I added the CNAME's that he proposed and everything went find. I've updated my question with what works. Now I just need to figure out how to redirect the www's to a non-www https
    – bryan
    Sep 4, 2014 at 1:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.