Rack rewrite remove urls trailing slash

If you’re after a solution to remove trailing slashes in URLs using Rack rewrite, read on…. Rack rewrite remove URLs trailing slash so Google and other Search Engine don’t consider and as being 2 different pages with duplicate content.

But first, visit the 301 redirect all non www to www using rack rewrite to see how to install your gem and learn about other 301 redirects that might come handy for complementary SEO purposes.

Rack rewrite remove urls trailing slash

Create (or edit if already existing) the code in an initializer (config/initializers/rack_rewrite.rb) as follow:

config.middleware.insert_before(Rack::Lock, Rack::Rewrite) do
     r301 %r{^/(.*)/$}, '/$1'

That’s it… simple!


For further info, please visit

IT Support Newcastle is brought to you by Transcendit Ltd, contact us on 0191 482 0444