Find file
Fetching contributors…
Cannot retrieve contributors at this time
50 lines (32 sloc) 1.22 KB


Use this rack module if you want to have your application respond to just one domain name and redirect any other the domain.

For example when your applicaiton responds to both www and non www prefixed domain name, or to both and

Redirect preserves path and querystring.


Add this line to your application's Gemfile:

gem 'rack-canonical-hostname', :require => 'rack/canonical_host'

And then execute:

$ bundle

Or install it yourself as:

$ gem install rack-canonical-hostname


Configure three options:

  • host: the actual canonical host name for your site
  • scheme: redirect to http or https. Default to http
  • ignore: an array of hostnames to ignore

Example for rails configuration:

  config.middleware.insert_before Rack::Lock, Rack::CanonicalHost, {
    :host   => '',
    :scheme => 'https',
    :ignore => ['', '']


  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request