Url rewrite options

My site have only one category (used cars) and many search options (faceted search), sorting and pagination. I use mod_rewrite (key/value -> key=value) to make URLs like this:

/used-cars/brand/ford/model/fiesta/fuel/diesel/sorting/price-asc/page/2
/used-cars/model/fiesta/variant/1.4-tdci/equipment/cd

Now, I need to add more categories and subcategories, and URLs should be LIKE this:

/vehicles
/vehicles/used-cars
/vehicles/used-cars/brand/ford/model/fiesta/fuel/diesel/sorting/price-asc/page/2
/vehicles/model/fiesta/variant/1.4-tdci/equipment/cd

As you can see, categories and subcategories are not key/value pairs, and may be just one category, or category/subcategory or category/subcategory-L1/subcategory-L2.

  1. First problem is how to delimit categories and key/value pairs (brand/ford…) to be able to parse it properly?
  2. Second problem is how to identify category (names are not unique)

I searched to see how other sites do this, and I found a lot of not-so-good solutions, and some that could be acceptable in the absence of better solutions.

Those deals with delimiting problem only:

/vehicles/used-cars/search/brand/ford/model/fiesta/fuel/diesel/sorting/price-asc/page/2
/vehicles[COLOR=“Red”]/[1]model/fiesta/variant/1.4-tdci/equipment/cd

And other that deals with both problems:

/vehicles/used-cars/cid16/brand/ford/model/fiesta/fuel/diesel/sorting/price-asc/page/2
/vehicles/used-cars-cid16/brand/ford/model/fiesta/fuel/diesel/sorting/price-asc/page/2

What is your suggestions?

Is it better way to store path (to the root) for each category and match it with category path from URL, or to use category_id in URL?

I hope that someone will understand me! :slight_smile:


  1. /COLOR ↩︎

If the names are not unique, as you say, there is no way you can find out which category was meant without knowing the key in the database, i.e., the cid16 part.

I would definitely go with that second option; even though the URLs might look a bit worse, they’re less ambiguous. The first option will only get you into trouble.

As far as the difference between the first URL and second URL of the second option goes, that’s personal preference I’d say. I prefer the first one, but others might feel differently. Just pick the one you think is best.
I suppose there is something to be said that the second option has less “directories” so should be (marginally) better for search engine optimization. But that’s mostly speculation TBH.