Skip to content

Instantly share code, notes, and snippets.

@menkel
Created June 4, 2012 10:08
Show Gist options
  • Save menkel/2867602 to your computer and use it in GitHub Desktop.
Save menkel/2867602 to your computer and use it in GitHub Desktop.
non-www to www redirection for heroku
class WwwRedirect
def initialize(app)
@app = app
end
def call(env)
request = Rack::Request.new(env)
if request.host =~ /^mysite.com/
[301, {"Location" => request.url.sub("//", "//www.")}, self]
else
@app.call(env)
end
end
def each(&block)
end
end
config.autoload_paths += %W(#{config.root}/lib)
config.middleware.use "WwwRedirect"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment