Project

rack-www

0.03
No commit activity in last 3 years
No release in over 3 years
Rack middleware to force subdomain redirects.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 2.13
~> 5.8
~> 0.6
~> 10.4

Runtime

< 3.0
 Project Readme

Build Status

rack-www

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

Installation

  gem 'rack-www'

Usage

Usage (by default it will redirect all requests 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:

  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|
    !Rack::Request.new(env).params.has_key? "noredirect"
  }

Specifying host-regex to determine on what hosts to redirect:

  config.middleware.use Rack::WWW, :host_regex => /example/i

This will only redirect when the host matches example, such as example.com or example1.com. It won't redirect on localhost or any other host that does not match the regex

It ignores any redirects when using IP addresses.

Options

  • :www => default is true, redirects all traffic to www;
  • :subdomain => redirects to any given subdomain;
  • :message => display a message while redirecting;
  • :host_regex => redirects if the given host match

License

MIT License. Copyright Jhimy Fernandes Villar http://stjhimy.com