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 |
# File 'lib/locomotive/middlewares/seo_trailing_slash.rb', line 9 def call(env) path, query = env['PATH_INFO'], env['QUERY_STRING'] if !path.starts_with?("#{Locomotive.mounted_on}/") && (match = path.match(%r{(.+)/$})) url = self.redirect_url(match[1], query) self.redirect_to(url) else @app.call(env) end end |