Use a regular expression in a URL redirect

Cassy_Jens
New Member
2 0 0

Does anyone know whether regular expressions or similar are supported in the Shopify URL Redirect?

I need to add a URL Redirect in Shopify that uses a regular expression (or similar) to capture the product handle from the Shopify URL and insert it into the redirect URL, which happens to be a URL outside of Shopify. For example, my original URL is https://my-company.myshopify.com/store/item-1, and I need to redirect it to https://my-company.co/store/item-1. ;

I'd like to do this with a regular expression because I have over 100 items, and I do not want to add them all and have to maintain the list every time a new product is added to Shopify.

I am able to add URL redirects for static URLs successfully, using the guide here. https://docs.shopify.com/manual/your-website/navigation/url-redirect

However, I am unable to capture a part of the original and re-use it in the redirect URL successfully. I have tried variations of the following, but I would expect that if regular expressions are supported, they would function like an .htaccess file. And the first regular expression has been proven to work in an .htaccess file. Is there another mechinism that would function similarily that Shopify supports?

https://my-company.myshopify.com/store/([a-zA-Z0-9_-]*)(/)?$ -> https://my-company.co/store/$1

https://my-company.myshopify.com/store/(.)* -> https://my-company.co/store/$1

All attempts have resulted in a 404 result on Shopify's end instead of a redirect.

0 Likes
Cassy_Jens
New Member
2 0 0

Hi Shane. Thank you for your reply. Fwiw, as a workaround I created a little Node app which cycles through all of the products in my Shopify store and creates the necessary URL redirects using the Shopify API. Anytime a new product is added to the store, we trigger the program to run for the new product. This was a nice alternative to avoid manually creating the redirects, although regex support would still be a nice option. Thanks in advance for keeping the thread updated should this feature enter the roadmap.

0 Likes
Brian_Gerry
Shopify Partner
3 0 0

This remains to this day to be one of the cons of Shopify. You can do this with WooCommerce and Miva very easily but not with Shopify. 

0 Likes