How can I redirect sold out products to their original category?

Topic summary

A user seeks to redirect sold-out or archived products to their original collection pages instead of the homepage.

Proposed Solutions:

  • Third-party app: StephensWorld suggests using an app (Nada’s Hide Out of Stock) that automatically hides sold-out products and creates URL redirects.

  • Shopify Flow customization: DaveMcV recommends modifying the “Create redirect URLs when a product’s status changes” template. This involves iterating over product.collections using a “For each” action to generate redirects for each collection the product belongs to. An example workflow image and Liquid code snippets are provided showing how to set redirect paths dynamically.

  • Metafield approach: ecom_ryan proposes a simpler method using a single-line text metafield (e.g., ‘url-friendly-vendor-handle’) to store the collection’s URL-friendly handle. A Flow would then create two redirects when a product status changes from active to archived, targeting both the product URL and collection-specific URLs.

Key Considerations:

  • Products may belong to multiple collections, complicating redirect logic.
  • The metafield solution works best when products are primarily associated with vendor collections.
  • An additional question arises about hiding products/collections via Flow, which remains unanswered.
Summarized with AI on November 5. AI used: claude-sonnet-4-5-20250929.

i am trying to create a flow to re-direct products that are sold out and/or for which their product status has changed to archive/draft to the collection/category they were apart of. currently when this situation occurs we just re-direct them to the home page (shop url)? is there any way to do this as i was looking at the shopify flow templates and they all seem to re-direct to shop url?

I’m not sure how to do this with the Shopify Flow App, but there is an app on the Shopify App Store which could handle this for you.

https://apps.shopify.com/nada-sort-hide-out-of-stock

It’ll hide your sold-out products, and then automatically create URL redirects for them.

we currently hide all of our sold put products and redirect these pages to our home page. rather than directing them to the home page (for seo purposes) would like to redirect them to the collection that the product belongs to? trying to determine how we might be able to do this?

Hi @marcces ,

The Create redirect URLs when a product’s status changes template can be customized to use a relative path and look at the product’s collections. This logic will be unique to your shop based on your usage of collections. You could consider iterating over the product.collections list and update the URL for each one rather than using the hard coded collection name in the example.

Here’s an example to consider as you’re building:

The first redirect for the product URL will redirect to the first collection in the list, using the liquid:

/collections/{%- assign first_collection = product.collections | first -%}{{first_collection.handle}}

Then to update the links for each of the collection-specific URLs, you’ll need to use the For each action to iterate over product.collections. The on the body, you can set the path/target as follows:

Path:
/collections/{{collectionsForeachitem.handle}}/products/{{product.handle}}

Target:
/collections/{{collectionsForeachitem.handle}}/

This will likely need to be tweaked for your specific use case, but it’s a starting point to consider. You can follow the same general logic flow for when the product goes out of stock too.

Hope that helps!

1 Like

Hi Dave, if you want the redirect to go to the products collection/‘vendor name’ url, what would you change in your example ? My products can be in multiple collections

thanks

A far simpler solution to this is to just add a single line text product metafield definition and input the URL friendly version of the vendor collection. Name this definition ‘url-friendly-vendor-handle’ or something. For example:

If your collection name is Coffee Mugs, the URL friendly version is probably ‘coffee-mugs.’ It would look like ‘/collections/coffee-mugs’ in your browser address bar.

Next, create a Flow that checks to see if the product status switches from active to archived and then tell it to create two URL redirects:

1st Redirect

From Path: /products/{{product.handle}}

To Path: /collections/{{product.urlFriendlyVendorHandle.value}}

2nd Redirect

From Path: /collections/{{product.urlFriendlyVendorHandle.value}}/products/{{ product.handle}}

To Path: /collections/{{product.urlFriendlyVendorHandle.value}}

When any active product is archived, this will automatically create two URL redirects that point to the vendor collection. This is a very simple, and sustainable method for targeting the two heavy-hitting URL’s for products. If your products live in multiple collections, and they probably do, there isn’t a simple option like this as it would be an administrative nightmare to include all the URL friendly handles for those collections.

Hope this helps.

How do you hide them with a flow? Is it possible to hide a collection too?