Ask A Question

Notifications

You’re not receiving notifications from this thread.

How do I generate SEO Friendly URL's for filter combinations in Rails?

Tommy asked in General

I have a site where the user can apply a combination of multiple filters.

To improve the SEO on the site I would like to have the URL in a human-readable format when filters are applied.

I would like the URL to be:
example.com/stadiums-in-england-or-spain-with-grass-and-capacity-of-more-than-20000

Instead of:
example.com/country=england,spain&surface=grass&with_capacity_of_more_than=20000

This is something that I've seen on NomadList where for example, if the user applies the filter 'walkable' and 'Europe the generated URL will be
https://nomadlist.com/walkable-places-in-europe

Anyone here has any idea on how to build this?

Reply

Hey Tommy!

You would probably need to do this with wildcard URLs and then parse them.

# At the very bottom of your routes file so it doesn't override other GET routes
get "*place" => "places#show"

This should assign params: { place: "walkable-places-in-europe"}

And you could parse that string with Regex or similar to get your filter and location out of it in the controller.

Reply

That's great sharing! I did

Reply

Good question and nice answer, thx Chris Oliver

Reply

You would have to make sure your site has been indexed first and then make it friendly!

Reply

I'm working with a client that is looking to build a page to feature products with filters/facets.

Reply

Hey Tommy, generating SEO-friendly URLs with filter combinations in Rails is a great idea for improving user experience and SEO ranking. You can achieve this using friendly_id gem or by customizing your routes and controllers. Also, you can buy seo traffic. I've done something similar for a project. I am happy to share some tips if needed!

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 82,329+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.