Skip to content

Instantly share code, notes, and snippets.

@krigar
Created July 16, 2015 09:33
Show Gist options
  • Save krigar/4ab7830d6b5f428fa044 to your computer and use it in GitHub Desktop.
Save krigar/4ab7830d6b5f428fa044 to your computer and use it in GitHub Desktop.
Rack::Redirect
module Rack
class Redirect
def initialize(app)
@app = app
end
def redirect(location)
[301, {'Location' => location, 'Content-Type' => 'text/html'}, ['Moved Permanently']]
end
def call(env)
redirects = { “/obsolete-page” => “/new-page” }
req = Rack::Request.new(env)
return redirect(redirects[req.path]) if redirects.include?(req.path)
@app.call(env)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment