Forum

Thread tagged as: Question, Shop

Perch Shop - URL Advice

Hi Drew,

I'm building a Perch Shop and for SEO reasons what to include the full category path in the product page route, for example

/products/timber/cladding/**my-product**

The problem is, sometimes a category has a subcategory, eg:

/products/timber/cladding/softwood

This renders the route wrong for some product pages, and category pages. What would you suggest as an implementation here?

Thanks, Ryan.

Ryan Gittings

Ryan Gittings 1 points

  • 3 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

What have you tried? I think this should work.

products/[slug/slug:catPath]/[slug:product]
products/[slug:catPath]/[slug:product]
Ryan Gittings

Ryan Gittings 1 points
Registered Developer

That worked fantastically, you're a star Drew! To get a product's URL, is this the best approach:

/<perch:categories id="category" set="products" label="Category"><perch:if exists="perch_item_last"><perch:category id="catPath" /></perch:if></perch:categories><perch:shop id="slug" type="slug" />, in it's own template then reused where I need the link?

Cheers!

Ryan Gittings

Ryan Gittings 1 points
Registered Developer

Ah it's so close to working!

Two URL's:

/products/timber/decking/q-deck/
/products/stoves/esse/esse-100

They clash when I set products/[slug/slug/slug:catPath]

The problem is technically the routes are the same, could either be a category page, or a product page.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Take the last segment. Look to see if it's a product. If it's not, you're on a category page.

Ryan Gittings

Ryan Gittings 1 points
Registered Developer

Yep that'll work! Thanks Drew.