Skip to content

Instantly share code, notes, and snippets.

@stve
Forked from trevorturk/no_www.rb
Created February 5, 2010 05:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stve/295529 to your computer and use it in GitHub Desktop.
Save stve/295529 to your computer and use it in GitHub Desktop.
class NoWWW
STARTS_WITH_WWW = /^www\./i
def initialize(app)
@app = app
end
def call(env)
if env['HTTP_HOST'] =~ STARTS_WITH_WWW
[301, { 'Location' => Rack::Request.new(env).url.sub(/www\./i, '') }, ['Redirecting...']]
else
@app.call(env)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment