Skip to content

Instantly share code, notes, and snippets.

@nicinabox
Created December 6, 2011 21:19
Show Gist options
  • Save nicinabox/1440049 to your computer and use it in GitHub Desktop.
Save nicinabox/1440049 to your computer and use it in GitHub Desktop.
class CanonicalRedirect
def initialize(app)
@app = app
end
def call(env)
request = Rack::Request.new(env)
if request.host =~ /^example.com/
[301, {"Location" => request.url.sub("//", "//www.")}, 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