Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Rack middleware to force subdomain redirects, e.g: www.

branch: master

Fetching latest commit…


Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 test
Octocat-spinner-32 .gitignore
Octocat-spinner-32 CHANGELOG.rdoc
Octocat-spinner-32 LICENSE
Octocat-spinner-32 README.rdoc
Octocat-spinner-32 Rakefile
Octocat-spinner-32 rack-www.gemspec


Rack middleware to force subdomain redirects, e.g: www.


#default installation
gem install rack-www

#when using bundler
gem 'rack-www'


Default usage (by default will redirect all requests to www subdomain):

#redirects all traffic to www subdomain
config.middleware.use Rack::WWW

Customizing the :www option to true or false:

#redirects all traffic to www
config.middleware.use Rack::WWW, :www => true

#redirects all traffic to the same domain without www
config.middleware.use Rack::WWW, :www => false

Redirecting to a given subdomain:

#redirects all traffic to the 'secure' subdomain
config.middleware.use Rack::WWW, :subdomain => "secure"

If you like it's also possible to show a message while redirecting the user:

config.middleware.use Rack::WWW, :www => false, :message => "You are being redirected..."

You can optionally specify predicate to determine if redirect should take place:

config.middleware.use Rack::WWW, :predicate => lambda { |env|
  ! "noredirect"


  • :www => default is true, redirects all traffic to www;

  • :subdomain => redirects to any given subdomain;

  • :message => display a message while redirecting;


MIT License. Copyright 2011 Jhimy Fernandes Villar.

Something went wrong with that request. Please try again.