Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating SEO friendly URLs in Rails 3

I currently have URLs which look like this:

things?category_id=6&country_id=17

and I would like to have URLs which look like this:

/printer_cartridges/united_kingdom

Is there a way in Rails 3, without hard coding all of the categories and countries in the router to have the URLs as I would like above, perhaps using find_by_name or the such like? What is the best way to approach this?

like image 315
Gav Avatar asked Feb 14 '11 18:02

Gav


People also ask

What is SEO friendly URL give example?

URLs that are simple, easy to read, and include keywords that describe the content on a web page are SEO-friendly. For example, if you're searching for information about pancakes, a URL like https://en.wikipedia.org/wiki/pancake will help you decide to click on that link.

What is SEO friendly URL in SEO?

SEO friendly URLs are URLs that are designed to meet the needs of users and searchers. Specifically, URLs optimized for SEO tend to be short and keyword-rich.

How can I get SEO friendly URL in asp net?

But to ensure the URL to be SEO friendly we need to change the “id” to contain a name. There can be multiple records with the same name existing in the database. That creates an issue while using a name of a record as “id” or key. Here, I will be using the name and id combination to get the uniqueness for the view.


1 Answers

match '/:category_slug/:country_slug', :to => 'things#index'

Then you'll need to update your action to look up everything using params[:category_slug] and params[:country_slug] instead of the ids. Look at the slugged gem to generate slugs.

like image 120
Jordan Avatar answered Sep 30 '22 12:09

Jordan