2011-06-22 15:53:29 +00:00
|
|
|
module Locomotive
|
|
|
|
module Middlewares
|
|
|
|
class SeoTrailingSlash
|
|
|
|
|
|
|
|
def initialize(app, opts = {})
|
|
|
|
@app = app
|
|
|
|
end
|
|
|
|
|
|
|
|
def call(env)
|
|
|
|
path = env['PATH_INFO']
|
|
|
|
|
2011-11-27 07:22:00 +00:00
|
|
|
if !path.starts_with?('/admin/') && (match = path.match(%r{(.+)/$}))
|
2011-06-22 15:53:29 +00:00
|
|
|
response = Rack::Response.new
|
|
|
|
response.redirect(match[1], 301) # moved permanently
|
|
|
|
response.finish
|
|
|
|
response.to_a
|
|
|
|
else
|
|
|
|
@app.call(env)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|