-
-
Save ivan-leschinsky/096b67c53171e6c517df to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Configure Rack middleware | |
config.middleware.insert_before 0, 'WwwRedirect' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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