I'm a new sysadmin attempting to set up a series of sites that rewrite the non-www versions of their URLs to the www versions. I know this is a topic that has been beaten to death, but I've scoured the internet and can't find any answers.
So: My site should live at www.example.com. I have tried setting up DNS in Amazon's Route 53 for www.example.com as my apex domain, as well as example.com with a CNAME alias for the www variant.
I can get my site to respond to the naked domain without any problems, and to alias the www version to non-www through that CNAME alias above. I however cannot get DNS to resolve for the www version. Currently the name servers are pointing to the www DNS records.
I can tell that my server is getting hit because refreshing the naked domain correctly rewrites the URL and displays in the access log. However, DNS does not resolve for the www variant.
Again, if I switch everything over to the non-www version, I have no issue serving the site and redirecting from www to non-www. It's just getting the www DNS to resolve that's driving me up the wall.
Below is my Apache virtual host config.
<VirtualHost *:80>
ServerName www.example.com
ServerAlias example.tbid.promocampaigns.com
ServerAlias example.com
ServerAdmin [email protected]
DocumentRoot /var/www/public_html/example.tbid.promocampaigns.com/
CustomLog /var/log/httpd/example.tbid.promocampaigns.com-access_log combined
TransferLog /var/log/httpd/example.tbid.promocampaigns.com-transfer_log
ErrorLog /var/log/httpd/example.tbid.promocampaigns.com-error_log
<Directory /var/www/public_html/example.tbid.promocampaigns.com/>
allowoverride all
order allow,deny
allow from all
options +includes
rewriteengine on
</Directory>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/(.*) http://www.example.com/$1 [L,R]
</VirtualHost>
And my DNS in Route 53
www.example.com.
NS
<some name servers that I have directed Namecheap to use for domain name example.com>
www.example.com.
SOA
<first name server>
www.example.com.
A
<alias to load balancer>
It's got to be something very simple that I'm missing here - can anyone help me out?