12

I've registered several domains for my nieces and nephews, the idea being to create small static webpages for them, so they can say 'look at my website!'.

In terms of hosting it, I'm using expressjs on Heroku, to serve up static pages.

What I'm wanting to do is have:

http://suzy-derkins.space        -->    my-herokuapp.herokuapp.com/static/suzy
http://calvin-is-trouble.space   -->    my-herokuapp.herokuapp.com/static/calvin

Now I can user a CNAME record to point each of my domains at my-herokuapp.herokuapp.com, but a CNAME record won't allow a full URL.

I could add an unmasked redirect, so that

http://suzy-derkins.space redirects to https://suzy-derkins.space/static/suzy, but that's ugly.

I don't want to use a masked URL redirect - as that causes problems on mobile, and also the user presses any links, the new page remains masked.

I'd also like to retain the ability to add additional pages, for example:

http://my-herokuapp.herokuapp.com/static/suzy/my-favourite-things be represented by http://suzy-derkins.space/my-favourite-things.

What kind of records do I use to do this?

1
  • What sort of additional Virtual-Host / Addon domain / URL rewriting capability does Heroku provide? Unless you can do something like this, or Heroku provides some kind of specific feature, then an "external redirect" might be the only option. Short of creating an another "account"? There are no ordinary (DNS?) "records" that can do this.
    – MrWhite
    Dec 26, 2016 at 12:27

1 Answer 1

5

DNS records alone cannot do what you want. DNS records only point host names to IP addresses (or in the case of CNAMEs to other host names).

You have to configure your server to handle it correctly.

One way is to issue redirects. I presume that you think that is ugly because the URL changes.

Another way is to set up "virtual hosts" with different content for each of these host names. I've never used Heroku before, but it appears that you can add multiple custom domains to it: https://devcenter.heroku.com/articles/custom-domains

In a single application with multiple host names pointed at it you can usually discern the host name and program your application to act accordingly. I haven't been able to figure out how to do so in Heroku, but it should be part of the HTTP Request. It is sent as the Host: HTTP header.

1
  • Hi thanks. It looks like that heroku documentation link is what I'm looking for.
    – dwjohnston
    Jan 25, 2017 at 21:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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