4

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.

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

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

4

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.

2

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.

1

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

0

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

0

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.

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.