A Shopify store owner wants to restructure product URLs from the default /products/product-name format to include collection paths like /collection/baby-product/products/product-name.
Proposed Solutions:
Update product links in collection files by changing {{ product.url }} to {{ product.url | within: collection }}
Modify the product-card.liquid file to concatenate collection and product URLs
Working Solution (Marked as Resolved):
The original poster found success by editing product-card.liquid, replacing the standard product URL code with logic that:
Extracts clean URLs by removing query parameters using split: '?' | first
Retrieves the first collection URL via product_card_product.collections.first.url
Concatenates collection and product URLs: href="{{ collection_url }}{{ product_url }}"
Benefits Identified:
Improved SEO through category hierarchy reinforcement
Better user experience by maintaining collection context during navigation
Cleaner URLs without tracking parameters
Note: One participant clarified that Shopify’s core URL structure (/products/ and /collections/) cannot be fundamentally changed, though handles can be customized.
A follow-up question asks about creating custom URL patterns like Home/collection-name/product-name, which remains unanswered.
Summarized with AI on October 30.
AI used: claude-sonnet-4-5-20250929.
I’d be happy to share some information around this for you.
Shopify’s URL structure is static, and can’t be changed. All product and collection URLs will follow the same naming structure, which should look like this:
You can change the product-name-handle or collection-name-handle in the SEO section of that specific product or collection. The handle used in the URL is based on the name given to the product when it is first created, but can be updated at any time.
I hope that answers your question. Please let me know if you need more information about your page structures.
The core logic behind this modification is ensuring that product links include the collection URL, making them more structured and relevant to the browsing context. Here’s what the code does:
Extracting Clean URLs:
The split: ‘?’ | first operation ensures that any query parameters (like tracking codes) are removed from both the product and collection URLs.
This keeps the URLs clean and prevents unnecessary duplication of parameters.
Getting the Collection URL:
product_card_product.collections.first.url retrieves the URL of the first collection associated with the product.
If the product belongs to multiple collections, this will always take the first one.
Concatenating Collection and Product URLs:
The new href is formed by appending the product’s URL to its collection URL:
href=“{{ collection_url }}{{ product_url }}”
This modifies the product link to start from the collection URL, making navigation more structured.
Expected Outcome- Instead of linking directly to the product page, it now directs users through the collection page.
Helps in SEO by reinforcing the category hierarchy.
Provides a better user experience by maintaining category context.