I have a domain for my site:
example.com
I am also running local DNS with these lines:
www IN CNAME server.<host_provider>.com.
dev IN CNAME server.<host_provider>.com.
So www.example.com
and dev.example.com
go to production and development sites, respectively, that are hosted by a host company.
In my Apache configuration for the main site, I'm running a rewrite rule like this:
RewriteEngine ON
RewriteCond %{HTTP_HOST} ^example\.com$|!dev\.example\.com$ [NC]
RewriteRule ^(.*)$ http://www\.%{HTTP_HOST}/$1 [R=302,L,NE]
This rule seems to work, as when you are off the network and go to example.com
in the browser, you get redirected to www.example.com
.
The problem is when I'm on the network, and I go to example.com
I get an error page, saying page can't be found. No server errors; just a page can't be found, as if the local DNS is causing it to stop looking at that point.
I'm also using Nettica for DNS service and have this A record in place:
example.com Host (A) Default xxx.xx.xxx.xx
This handles the external DNS, but my problem seems to be related to my internal DNS.
For example, inside my network, I can go to servers on the network with addresses like this:
server.example.com
server1.example.com
server2.example.com
These are configured in my local DNS. I'm just not sure how to get past the "empty" subdomain and go to example.com
.
Adding to this since it might not be clear. If I'm out side the example.com
network, on another network, like example123.com
, then when I go to example.com
I'm redirected to www.example.com
as expected, eg, the Apache rewrite rule is working.
EDIT
With the help of @ErikE and troubleshootinig and testing, I found an answer. Seems I discovered another way along with @ErikE's suggestion:
In local DNS adding either one of these seems to work:
example.com IN CNAME server.<host_provider>.com.
example.com IN CNAME www.example.com.
Thanks.
It sounds to me like you need an empty A record (or other record to the same effect) for the domain example.com itself in your local dns.
If I remember correctly (some time has passed since I last did this), in BIND this can be achieved using the following syntax in the zone file of example.com:
or in Windows DNS:
However, using dnsmasq for instance this would be configured in a completely different way. So, what brand of dns server are you using locally?
I am uncertain if one can write CNAME records in the same way. You could certainly try if you wish to refer to your provider instead of writing the ip addresses explicitly in your local dns.