Created
March 4, 2014 09:28
-
-
Save sethiele/9343134 to your computer and use it in GitHub Desktop.
Ruby Redirect Proxy
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
# encoding: utf-8 | |
class LegacyUrlProxy | |
URL_MAPPING = { | |
'//surgeons-for-africa.com' => '//surgeons-for-africa.org', | |
} | |
def initialize(app) | |
@app = app | |
end | |
def call(env) | |
request = Rack::Request.new(env) | |
dest_url = URL_MAPPING[request.path_info.gsub(/\/$/, '')] | |
if dest_url | |
[301, {'Location' => request.script_name + dest_url}, ['']] | |
else | |
@app.call(env) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment