Redirection work-arounds in Shopify

Category: Development | July 2023.

Shopify has a great url re-direction facility in the admin, but this only works for 404 errors. If the page actually exists, and it’s a core page so you can’t remove it, a workaround is required. A common scenario is that access to the collections-list page may want to be blocked, with all traffic going to the shop landing page instead, where everything is more structured. Especially since the “Continue shopping” button in the checkout page often links to this page and, and as far as I can tell, there is no way of changing the target of this button.

It took a while for me to find the workaround on the forums so I thought it was worth sharing here.

Adding this code to the theme.liquid file worked a treat:

<script>if (window.location.pathname === '/collections' || window.location.pathname === '/collections/' || window.location.pathname === '/products' || window.location.pathname === '/products/') {
window.location.href = '/pages/shop';