SEO - 301 redirect a subdomain to the main domain (sudirectory) with URL matching

Topic summary

A Shopify store needs to migrate from Langify V1 to V2, requiring a 301 redirect from a subdomain (es.website.com) to a subdirectory structure (www.website.com/es/) while preserving URL paths.

Challenge:

Proposed Solutions:

  1. Manual approach: Use Shopify’s built-in redirect app or easy redirect apps

  2. CloudFlare (recommended):

    • Free tier includes 3 page rules (additional rules available at $5 for 10)
    • Setup takes ~15 minutes via DNS configuration
    • Enable orange cloud proxy on subdomains being redirected
    • Critical warning: Do NOT enable orange cloud on www domain serving Shopify content (Shopify already uses CloudFlare; conflicts occur without Enterprise plan)
    • Supports RegEx redirects at the edge
  3. Liquid theme code: Add custom script in theme’s tag (specific code provided by late commenter)

Status: Multiple viable solutions presented; CloudFlare appears most robust for pattern matching requirements.

Summarized with AI on November 11. AI used: claude-sonnet-4-5-20250929.

Hi Shopify community,

We are looking to redirect a subdomain like https://es.website.com/ to https://www.website.com/es/ as we need to upgrade our version of Langify from V1 to V2.

The URLs path will not change and we are looking to achieve the following:

  1. Redirect using 301 Permanent Redirect our subdomain to the main domain.
  2. Match the URL paths so that https://es.website.com/collections/collection-1 will automatically redirect to https://www.website.com/en/collections/collection-1, https://es.website.com/collections/collection-2 will automatically redirect to https://www.website.com/en/collections/collection-2, https://es.website.com/product/product-1 will automatically redirect to https://www.website.com/es/product/product-1 and so on.

Unfortunately, we can not easily add a RegEx (Regular Expression) as we could have done if we had access to the .htaccess file, like the one below :


Any idea about the best way to achieve such redirect in Shopify?

Thanks a lot,

Dear @Killian

Either do it manually or use easy redirect Shopify app

The easy way is use CloudFlare for free you get 3 page rules these are most of the time plenty to do what you need.

If you do need more I believe they sell them at $5 for 10 pages rules

The time it takes you to change your DNS over to CloudFlare is literally under 15 minutes

remember when you set up the DNS for your DNS make sure that the orange cloud is on for the subdomains you want to redirect

See the orange proxy toggle

CloudFlare any cast DNS is free and one of the fastest on the planet making it one of the best values in the world.

With the gray cloud on the DNS it acts like any other high-quality DNS however when you turn the orange cloud turns on the proxy on.

You Will have on the edge regex redirects on the edge allowing you to create redirects with regex

https://support.cloudflare.com/hc/en-us/articles/360037345072-Getting-Started-with-Cloudflare-Video-Tutorials

(DO NOT USE IT ON THE URL SERVINGS CONTENT via Shopify in your case it’s the www)

(Shopify uses CloudFlare already & unless you have CloudFlare Enterprise Do not use CloudFlares orange cloud on your www

but it must be on the Subdomain your redirecting to your subfolder in your example case you can use it on your bare domain only if you have a www. serving the final content.

Page Rule subdomains require an “Orange Clouded” DNS record for the Page Rule to work. Page Rules won’t apply to subdomains that don’t exist in DNS or aren’t being directed to Cloudflare.

https://support.cloudflare.com/hc/en-us/articles/200172286-Configuring-URL-forwarding-or-redirects-with-Cloudflare-Page-Rules

Regex

https://support.cloudflare.com/hc/en-us/articles/218411427-Understanding-and-Configuring-Cloudflare-Page-Rules-Page-Rules-Tutorial-

Fastly this is not as simple but here is some information I have written about this issue.

Go to reply 2 on this

https://moz.com/community/q/are-our-subdomains-detrimental-to-our-seo-efforts?sort=oldest

https://moz.com/community/q/using-a-reverse-proxy-and-301-redirect-to-appear-sub-domain-as-sub-directory-what-are-the-seo-risks#reply_403657

Let me know if you have any questions this whole procedure takes literally 25 minutes and it’s a very good price if you consider the cost and apps

I hope this helps,

Tom

I know I’m a bit late with my reply. But we recently came across the same issue. For whoever it may help, the script below works for us. Just place it right below the tag of your theme.liquid:


Cheers!