Advertisement
Guest User

Untitled

a guest
Apr 19th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.29 KB | None | 0 0
  1. class NoWWW
  2.  
  3. STARTS_WITH_WWW = /^www\./i
  4.  
  5. def initialize(app)
  6. @app = app
  7. end
  8.  
  9. def call(env)
  10. if env['HTTP_HOST'] =~ STARTS_WITH_WWW
  11. [301, { 'Location' => Rack::Request.new(env).url.sub(/www\./i, '') }, ['Redirecting...']]
  12. else
  13. @app.call(env)
  14. end
  15. end
  16.  
  17. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement