0

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 dev@example.com
  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?

1

Simply enough, "www.example.com" is not a proper apex to use. Only "example.com" is.

Create a hosted zone in Route 53 for example.com.

Set your registrar up with the new servers for the new hosted zone.

Create two A records, one with the hostname blank, and the other with the hostname "www" and set both of them up as aliases pointing to the ELB.

You're done.

It sounds like what you've actually done is created DNS records for "www.example.com" and "example.com.www.example.com" ...

  • You're absolutely right. The revelation hit me when I reverted everything to the naked domains, got mobile redirected to m.example.com, got a DNS lookup failed, and realized I had no subdomain DNS records. Then it hit me that there's no 'magic' in the www subdomain, it's just another subdomain. Thanks for your help, mate. Definitely one of those problems where I spend a couple hours puzzling, write up the Stack Exchange post, and then find the solution 15 minutes later. – Tom Lagier Jul 3 '14 at 16:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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