Problem statement: You have a domain you want to redirect to some other domain. HTTPS redirects require both an active DNS zone, valid HTTPS certificate, and an SNI endpoint. This is not a free or automatic at many DNS hosts. My Redirect Dingus app can be deployed and configured once to support arbitrarily many domains and subdomain mappings, and can run on a single affordable eco dyno.
What is it? It's a tiny Heroku nginx app that simply reads a couple environment variables and uses them to map request hostnames to your intended redirect targets for cases when you have some number of domains and subdomains that should redirect to some other canonical domain.
For instance, Becky owns buildwithbecky.com, but wants it to redirect to betterwithbecky.com. And I own possyparty.com just in case anyone misspells posseparty.com.
So here's how to use this repo:
- Fork it
- Create a new Heroku app and provision an eco dyno to run nginx (see the repo's Procfile)
- Add the nginx buildpack with something like
heroku buildpacks:add --app your-app-name heroku-community/nginx
- Configure redirect domains (see below)
- Set up HTTPS by enabling Heroku automated certificate management
- Define domains (see below)
First, set your default/catch-all redirect domain to the REDIRECT_DEFAULT_DOMAIN
environment variable:
heroku config:set -a your-app-name REDIRECT_DEFAULT_DOMAIN="www.betterwithbecky.com"
Then, if you have multiple domains to redirect, you can set them to the REDIRECT_DOMAIN_MAP
environment variable as a JSON object with a single command like this:
heroku config:set -a your-app-name REDIRECT_DOMAIN_MAP='{
"members.buildwithbecky.com": "members.betterwithbecky.com",
"gram.buildwithbecky.com": "gram.betterwithbecky.com",
"admin.buildwithbecky.com": "admin.betterwithbecky.com",
"www.buildwithbecky.com": "www.betterwithbecky.com",
"buildwithbecky.com": "betterwithbecky.com",
"www.possyparty.com": "www.posseparty.com",
"possyparty.com": "posseparty.com"
}'
Each root domain and subdomain wildcard domain need to be specified (and effectively "claimed", as each domain can only be owned by a single Heroku application at a time) in the Heroku dashboard or CLI.
heroku domains:add yourdomain.com -a your-app-name
heroku domains:add *.yourdomain.com -a your-app-name
In my case, the custom domains look like this in the dashboard:
Once those have been specified, point each root domain to the goofily-named target generated by Heroku with an ALIAS
record (because you're using DNSimple, right?) and each wildcard domain with a CNAME
record.
In the case of POSSE Party, that looks like this in my DNS settings: