Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Rack middleware to redirect to your app's canonical host name

tree: 9574e8ae20

Fetching latest commit…


Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 spec
Octocat-spinner-32 .gitignore
Octocat-spinner-32 Gemfile Initial commit June 18, 2012
Octocat-spinner-32 LICENSE
Octocat-spinner-32 Rakefile
Octocat-spinner-32 rack-canonical-host.gemspec


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-host', :require => 'rack/canonical_host'

And then execute:

$ bundle

Or install it yourself as:

$ gem install rack-canonical-host


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
Something went wrong with that request. Please try again.