Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7863423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:28:41+00:00 2026-06-02T23:28:41+00:00

I have looked all over the internet but could not get one final solution

  • 0

I have looked all over the internet but could not get one final solution to what I would expect to be the 100% proper setup of DNS etc to get the following result on Heroku.com:

  • Using a mydomain.com to show the content at myapp.herokuapp.com
  • Redirecting all traffic from http://mydomain.com to http://www.mydomain.com (including subfolders)

I can get a bit of help from everywhere but nothing conclusive that will take care of the whole problem from DNS to rack-rewrite so that is why I am asking here (the support at my registrar and Heroku can only give me “their part”).

What needs to be done is, as far as I understand:

  1. Add mydomain.com and http://www.mydomain.com to Custom Domains at Heroku

  2. Change CNAME to http://myapp.herokuapp.com in my registrars DNS. Question: Would it be both “www” and “*” that would use the CNAME redirection to myapp.herokuapp.com?

  3. Add a “@” DNS record in order to handle naked domain requests (http://mydomain.com). Since this will not be done with CNAME, I am using the IP numbers at https://devcenter.heroku.com/articles/custom-domains, although they have severe uptime problems according to the article.

— 1-3 leaves me with a website that will serve both http://mydomain.com and http://www.mydomain.com with the content at http://myapp.herokuapp.com

c. Now, I want to redirect everything from http://mydomain.com to http://www.mydomain.com and, according to Heroku support, this should be done with rack-rewrite (https://github.com/jtrupiano/rack-rewrite). Using the example in there, the code should then be:

r301 %r{.*}, 'http://mydomain.com$&', :if => Proc.new {|rack_env|
  rack_env['SERVER_NAME'] != 'www.mydomain.com'
}

This, however, creates an eternal loop for me.

So, my question is now: What would be the proper workflow for Heroku and DNS-settings in order to achieve this setup?

It is very difficult to troubleshoot this, since trying out different DNS-settings by trial and error is very difficult (it’s hard to know if they have gone through).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T23:28:43+00:00Added an answer on June 2, 2026 at 11:28 pm

    It’s the rewrite rule I think that it is saying “do a 301 redirect to ‘http://mydomain.com$&’ (where the $& indicates that it will keep everything after the .com) but only if the host in the request is not ‘www.mydomain.com'”.

    So you’ll go into a redirect loop because any request to your server that doesn’t have the www in it, e.g. the naked mydomain.com, will redirect back to mydomain.com.

    It probably needs rewriting to something like:

    r301 %r{.*}, 'http://www.mydomain.com$&', :if => Proc.new {|rack_env|
    rack_env['SERVER_NAME'] == 'mydomain.com'}
    

    So you are redirecting to the www version of your domain.

    Actually there is a dupe here

    Edit:
    This is what I would do:

    1. remove your redirect rules
    2. set up your dns so that both http://www.domain.com and domain.com returns myapp.herokuapp.com
    3. verify that the dns works without worrying about redirection
    4. make sure that at the DNS level it isn’t trying to do some helpful redirecting

    At this stage there isn’t anything else to do with the DNS. The only thing they do is return an IP address (A record) or another domain (CNAME). Then their job is done.

    Next:

    1. Apply the rack-rewrite rule
    2. The server might need a restart – do it just in case
    3. Test using something like Sam Spade – the headers will contain a 301 redirect and the new location if it has worked properly
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have looked all over and found no solution, any help on this would
I know this is frequently asked, but I have looked all over the internet
I have looked all over the internet and haven't found my answer. Whenever one
I have looked all over the place but I cant seem to get this
I have looked all over the web and I can not find the information
I have looked all over but can't find an answer to this... Quite simply
I have looked all over the internet to try and solve this problem. Can
I have looked all over the internet to find an answer to my problem
I have looked all over the internet for an answer to my question to
I have looked all over the internet. Can anyone point me to some resources

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.