Is it possible to set a DNS record to redirect all example.com/*
traffic to www.example.com/*
?
I'm running a Sinatra app on Heroku's Cedar stack.
I set up Heroku's Custom Domains addon, and the documentation discusses Redirecting Traffic to a Specific Domain. I also read about how to do this with Rack Rewrite. However, I'm wondering if there's a way to do this via DNS, i.e., without hitting my app.
There is no way to do what you are asking for in DNS.
DNS simply resolves a hostname to an IP address there are no 'redirect' features
If you want users to only use your app via www.example.com you will have to do it in the app using the rack rewrite tip you linked to.
Assuming you're okay with changing your DNS servers, you can use DNSimple's "URL" DNS type. This will take care of your issue this at the DNS level.
It is mentioned in this Heroku article on Avoiding Naked Domains.
If you are on heroku the simplest way is a wildcard domain
This will redirect all subdomains *.example.com, including www to example.com.
If you have root access to your name server you must add:
or
for a wildcard where xxx.xxx.xxx.xxx is your IP, or
if you have an unknown/dynamic IP
If you use Google Apps, they have a feature that allows you to redirect your naked domain (http://example.com).
You simply add their servers as A records in your DNS.
Look in the Domain Settings of the Control Panel.
The URL should be like below. Just replace example.com with your domain.
https://www.google.com/a/cpanel/example.com/DomainSettingsDomains
Short answer: Point your "naked" domain record to
174.129.25.170
.Long Answer: The wwwizer.com is offering free redirection service. It redirects to whatever domain you attempted to go, just appending "www." before it. There is FAQ at http://wwwizer.com/naked-domain-redirect for those interested in details.