Skip to content

Instantly share code, notes, and snippets.

@trevorturk
Created November 3, 2009 05:03
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save trevorturk/224812 to your computer and use it in GitHub Desktop.
Save trevorturk/224812 to your computer and use it in GitHub Desktop.
no-www rack middleware
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