Class: Locomotive::Middlewares::SeoTrailingSlash
- Inherits:
-
Object
- Object
- Locomotive::Middlewares::SeoTrailingSlash
- Defined in:
- lib/locomotive/middlewares/seo_trailing_slash.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, opts = {}) ⇒ SeoTrailingSlash
constructor
A new instance of SeoTrailingSlash.
Constructor Details
#initialize(app, opts = {}) ⇒ SeoTrailingSlash
Returns a new instance of SeoTrailingSlash.
5 6 7 |
# File 'lib/locomotive/middlewares/seo_trailing_slash.rb', line 5 def initialize(app, opts = {}) @app = app end |
Instance Method Details
#call(env) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/locomotive/middlewares/seo_trailing_slash.rb', line 9 def call(env) path = env['PATH_INFO'] if !path.starts_with?("#{Locomotive.mounted_on}/") && (match = path.match(%r{(.+)/$})) response = Rack::Response.new response.redirect(match[1], 301) # moved permanently response.finish response.to_a else @app.call(env) end end |