Created
          July 16, 2015 09:33 
        
      - 
      
- 
        Save krigar/4ab7830d6b5f428fa044 to your computer and use it in GitHub Desktop. 
    Rack::Redirect
  
        
  
    
      This file contains hidden or 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
    
  
  
    
  | 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