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.

5 Answers 5


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

heroku addons:add custom_domains:wildcard

This will redirect all subdomains *.example.com, including www to example.com.

If you have root access to your name server you must add:

www   IN    A    xxx.xxx.xxx.xxx 


*     IN    A    xxx.xxx.xxx.xxx

for a wildcard where xxx.xxx.xxx.xxx is your IP, or

www   IN    A    myapp.heroku.com.
*     IN    A    myapp.heroku.com.

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.



Short answer: Point your "naked" domain record to

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.

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.