Blog



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 www.domain.com/page and www.domain.com/page/ 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'
end

That’s it… simple!

Resources:


For further info, please visit http://nanceskitchen.com/2010/05/19/seo-heroku-ruby-on-rails-and-removing-those-darn-trailing-slashes/


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