I want to change my current url structure of my site

Topic summary

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.

my current url structure is : https://theallinone.ca/products/newborn-baby-clothes-set-t-shirt-tops-pants-little-boys-and-girls-outfits to https://theallinone.ca/collection/baby-product/products/newborn-baby-clothes-set-t-shirt-tops-pants-little-boys-and-girls-outfits

i am using Ella Theme

1 Like

Hi @Sarveshtech you have to create a collection first like https://theallinone.ca/collections

Hi @Sarveshtech

You’ll have to update the product href’s from

{{ product.url }}

to

{{ product.url | within: collection }}

in your collection file.

NOTE: As file names can vary as per the theme so please check and update accordingly.

Please hit Like and mark as a Solution if it helps you.

Hi @Sarveshtech

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:

www.shopify.com/collections/collection-name-handle
www.shopify.com/products/product-name-handle

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.

can you tell what is the file name

i got the sollution go to this file : product-card.liquid
then replace this code :
to this code :

{%- liquid

assign product_url = product_card_product.url | split: ‘?’ | first
assign collection_url = product_card_product.collections.first.url | split: ‘?’ | first
-%}

We can change URL structure of our store:

Hey @Sarveshtech thanks for posting this solution
Can you please share the core logic behind this? like how this solution is working?
Regards

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:

  1. 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.
  2. 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.
  3. 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.

By any chance can I make my product URL to
Home/collection-name/product-name
and collection URL to
Home/collection-name