├── Gemfile ├── Gemfile.lock ├── config.ru └── README.md /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gem 'rack' 4 | gem 'rack-rewrite' -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | GEM 2 | remote: https://rubygems.org/ 3 | specs: 4 | rack (1.5.2) 5 | rack-rewrite (1.3.3) 6 | 7 | PLATFORMS 8 | ruby 9 | 10 | DEPENDENCIES 11 | rack 12 | rack-rewrite 13 | -------------------------------------------------------------------------------- /config.ru: -------------------------------------------------------------------------------- 1 | require 'rack/rewrite' 2 | 3 | # Expects ENV['REDIRECTS'] to be a ruby hash of source hostnames to destination hostnames. E.g.: 4 | # "{'old.domain.com' => 'new.domain.com'}" 5 | REDIRECTS = eval(ENV['REDIRECTS'] || '') || {} 6 | 7 | use Rack::Rewrite do 8 | 9 | REDIRECTS.each do |from, to| 10 | r301 %r{.*}, "http://#{to}$&", if: -> (env) { env['SERVER_NAME'] == from } 11 | end 12 | 13 | end 14 | 15 | # Fall back to default app (empty). 16 | run -> (env) { [200, {}, []] } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Rerouter 2 | 3 | A minimal, rack-based domain-redirecter. Generates 301 redirects from a set of source hostnames to their corresponding destination hostnames while preserving paths and querystrings. 4 | 5 | ## Steps for setting up your own rerouter on Heroku: 6 | 7 | git clone https://github.com/joeyAghion/rerouter.git 8 | cd rerouter 9 | gem install heroku 10 | heroku apps:create 11 | git push heroku master 12 | heroku config:set REDIRECTS="{'old.domain.com'=>'new.domain.com'}" 13 | heroku domains:add old.domain.com 14 | 15 | Then, update the DNS of `old.domain.com` to be a CNAME pointing to the new heroku app. 16 | --------------------------------------------------------------------------------