Overview of wildcard redirects in Shopify
Wildcard redirects (also known as pattern redirects) allow you to redirect all URLs that match a pattern to a new location. While standard URL redirects in Shopify must match the URL exactly, wildcard redirects allow you to do things like redirect all URLs that start with some text to a new location.
Since wildcard redirects are not supported natively by Shopify they function a little differently than URL redirects. When a visitor visits your Shopify store and access a URL that does not exist, the app will quickly check to see if there's a wildcard redirect that matches the URL. If there is, it will tell the visitor's browser to use that URL instead.
Wildcard redirects with Ablestar Link Manager perform faster than other apps and you will not see a flash of the 404 page with the redirects.
Parts of a wildcard redirect
Like URL redirects, wildcard redirects have two parts: 'redirect from' and 'redirect to'. The difference with the wildcard redirects is that you can put in placeholders into both of those fields. The placeholders start with the dollar sign and then a number from 1-5.
For example: /store/$1
would match any URL that starts with /store/.../
.
You can also use the placeholders in the 'redirect to' field. If you have a redirect from /$1/$2
to /new/$2
, the following redirects would work:
/old/product-one
->/new/product-one
/old/blog-article
->/new/blog-article
Using regular expressions (regex) for wildcard redirects
You can also use regular expressions if you need more control over your wildcard redirects. The regular expression will be evaluated from the start the path + query string. If you use capture groups in the regular expression, you can refer to those capture groups like $1
in the 'Redirect to' field:
Why use wildcard redirects in Shopify
Here are a few common situations where you might need to use wildcard redirects instead of standard URL redirects.
Redirect visits to all missing product detail pages
If you have unpublished a product from your store visitors will see a 404 error page if they try to access that product's URL. You can use wildcard redirects to send all visitors to missing product pages to another page.
For example, to send all visitors to a list of all your collections you can create a wildcard redirect like this:
- Redirect from:
/products/$1
- Redirect to:
/collections/all
Redirect all broken links to your homepage
You can redirect all broken link visits to a new URL by creating a wildcard redirect with 'redirect from' set to /$1
. Then anytime a visitor visits a page that does not exist they will be sent to which ever page you select.
Migrating to Shopify
If you are migrating to Shopify you might have a large number of URLs on your old store that no longer exist in Shopify. However you might have links to these URLs in Google, other blogs and social media sites. If these URLs follow a similar pattern you can use wildcard redirects to redirect your visitors to a new URL on your Shopify store.
For example, WooCommerce stores generally have products at URLs like /product/t-shirt
where as Shopify's URLs are like /products/t-shirt
(with the 's' on products). You could create a redirect for all product URLs with the following rule:
- Redirect from:
/product/$1
- Redirect to:
/products/$1
This would redirect URLs like /product/t-shirt
automatically to /products/t-shirt
so visitors could still find your products while following old links.
Uninstalling the app
Regular redirects that you create through the Link Manager are stored on Shopify and will persist even after you uninstall the app. Wildcard redirects though, require the app to function. If you uninstall the app, wildcard redirects will no longer work.