Skip to content

Instantly share code, notes, and snippets.

@jurgens
Created January 3, 2013 10:45
Show Gist options
  • Save jurgens/4442535 to your computer and use it in GitHub Desktop.
Save jurgens/4442535 to your computer and use it in GitHub Desktop.
class WWW
STARTS_WITH_WWW = /^www\./i
def initialize(app)
@app = app
end
def call(env)
if env['HTTP_HOST'] =~ STARTS_WITH_WWW
@app.call(env)
else
[301, { 'Location' => Rack::Request.new(env).url.sub(/^http:\/\//i, 'http://www.') }, ['Redirecting...']]
end
end
end
@jurgens
Copy link
Author

jurgens commented Jan 3, 2013

environments/production.rb:
config.middleware.use WWW

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment