Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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.

share|improve this question

migrated from stackoverflow.com Oct 10 '11 at 4:53

This question came from our site for professional and enthusiast programmers.

5 Answers 5

up vote 4 down vote accepted

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.

share|improve this answer

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 

or

*     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

share|improve this answer

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.

share|improve this answer

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

share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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