Skip to content

Instantly share code, notes, and snippets.

@ivan-leschinsky
Forked from brentertz/application.rb
Last active August 29, 2015 14:07
Show Gist options
  • Save ivan-leschinsky/096b67c53171e6c517df to your computer and use it in GitHub Desktop.
Save ivan-leschinsky/096b67c53171e6c517df to your computer and use it in GitHub Desktop.
# Configure Rack middleware
config.middleware.insert_before 0, 'WwwRedirect'
class WwwRedirect
def initialize(app)
@app = app
end
def call(env)
request = Rack::Request.new env
if request.host.starts_with? 'www.'
[301, { 'Location' => request.url.sub('//www.', '//'), 'Content-Type' => 'text/html' }, self]
else
@app.call env
end
end
def each(&block)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment