Regex Pattern Redirects

Common Regex Redirect Patterns in Shopify Swift Redirects App

Regex (regular expression) redirects let you bulk-redirect URLs that follow a pattern, instead of creating redirects one by one.

1. Wildcard Redirects (Match Everything After a Prefix)

Pattern:

/blog/(.*)

Redirect To:

/blogs/news/$1

Explanation: Redirects everything under /blog/ to /blogs/news/, keeping the slug.

Examples:

  • /blog/article-1/blogs/news/article-1
  • /blog/latest-update/blogs/news/latest-update

2. Remove Query Strings (UTM, Tracking Parameters)

Pattern:

/products/([a-z0-9-]+)(\?.*)?$

Redirect To:

/products/$1

Explanation: Strips UTM or query strings from product pages.

Examples:

  • /products/shirt?utm_source=google/products/shirt
  • /products/blue-jeans?ref=fb/products/blue-jeans

3. Force HTTPS or Remove “www”

Pattern:

http://(www\.)?example\.com/(.*)

Redirect To:

https://example.com/$2

Explanation: Redirects all http:// or www. traffic to secure non-www version.

Examples:

  • http://www.example.com/pagehttps://example.com/page
  • http://example.com/contacthttps://example.com/contact

4. Category Folder Redirects

Pattern:

/collections/old-collection/(.*)

Redirect To:

/collections/new-collection/$1

Explanation: Moves entire collection path.

Example: /collections/old-collection/shoes/collections/new-collection/shoes

5. Remove File Extensions (.html, .php)

Pattern:

/(.*)\.html$

Redirect To:

/$1

Explanation: Removes .html extensions from old migrated URLs.

Examples:

  • /about-us.html/about-us
  • /products/shirt.html/products/shirt

6. Trailing Slash Normalization

Pattern:

/(.*)/$

Redirect To:

/$1

Explanation: Removes extra trailing slashes.

Examples:

  • /contact//contact
  • /products/shirt//products/shirt

7. Handle Case Sensitivity

Pattern:

/Products/(.*)

Redirect To:

/products/$1

Explanation: Redirects uppercase/lowercase versions to the correct canonical one.

Example: /Products/Blue-Jeans/products/blue-jeans

8. Multiple Old Slugs → One New Page

Pattern:

/(old-page-1|old-page-2|old-page-3)$

Redirect To:

/new-page

Explanation: Multiple outdated URLs point to one updated URL.

Examples:

  • /old-page-1/new-page
  • /old-page-2/new-page

9. Date-Based Blog Redirects

Pattern:

/([0-9]{4})/([0-9]{2})/([0-9]{2})/(.*)

Redirect To:

/blogs/news/$4

Explanation: Strips old WordPress-style date paths.

Example: /2023/11/15/black-friday-sale/blogs/news/black-friday-sale

10. Force Lowercase URLs

Note: Not all apps support case-conversion tokens like \L.

Pattern:

/(.*[A-Z].*)

Redirect To:

/\L$1

Explanation: Converts uppercase to lowercase URLs (where supported).

Example: /Products/Blue/products/blue

Summary Table of Regex Redirect Patterns

Type Pattern Example Redirect Example
Wildcard Redirect /blog/(.*)/blogs/news/$1 /blog/post/blogs/news/post
Strip Query Strings /products/([a-z0-9-]+)(\?.*)?$/products/$1 /products/shirt?utm=1/products/shirt
Force HTTPS http://(www\.)?example\.com/(.*)https://example.com/$2 old → new domain
Move Collection /collections/old/(.*)/collections/new/$1 /old/product/new/product
Remove .html Extension /(.*)\.html$/$1 /about.html/about
Trailing Slash Fix /(.*)/$/$1 /page//page
Case Sensitivity /Products/(.*)/products/$1 /Products/abc/products/abc
Multiple Old → One New /(old1|old2)$/new /old1/new
Date Blog URLs /[0-9]{4}/[0-9]{2}/[0-9]{2}/(.*)/blogs/news/$1 /2023/11/11/test/blogs/news/test
Force Lowercase /(.*[A-Z].*)/\L$1 /Products/Blue/products/blue

Notes:

  • Shopify’s native admin redirect tool does not support regex. Use a redirect app that supports regex/pattern rules.
  • Some advanced tokens (like lowercase conversion) may not be supported in every app.
  • Always test patterns on a staging URL or with a small subset before bulk-activating.

Popular Post

Back to blog