Skip to content

Instantly share code, notes, and snippets.

@bitzesty
Forked from trevorturk/no_www.rb
Created December 29, 2009 13:48
Show Gist options
  • Save bitzesty/265320 to your computer and use it in GitHub Desktop.
Save bitzesty/265320 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 request.get? && 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