WordPress / 4 MIN READ
Redirecting Regex 101
Redirecting Regex 101
From the original Fervor library. Examples may use older package versions.
Absolutely! Below is a step-by-step tutorial to handle redirects from your main WordPress site to a WooCommerce store subdomain (e.g., store.yoursite.com) without harming SEO. This includes handling nested URLs like /product-category/firefighter-bags/mask-bags/.
Tutorial: Redirecting WordPress Product Categories to a Subdomain (SEO-Friendly)
Tools You’ll Need
- Access to your WordPress dashboard (old site and subdomain).
- Redirection Plugin (free).
- A spreadsheet tool (Excel/Google Sheets) to map URLs.
- FTP access (optional, for
.htaccessmethod).
Step 1: Pre-Launch Preparation
1.1 Backup Your Site
- Use a plugin like UpdraftPlus to backup both the old site and subdomain.
- Why? Avoid data loss if something goes wrong.
1.2 Map Old and New URLs
- Export all old URLs with
/product-category/using:- Screaming Frog (crawl your old site).
- WordPress Plugins like Export All URLs.
- Create a CSV with two columns: Old URL and New URL (e.g.,
https://yoursite.com/product-category/...→https://store.yoursite.com/product-category/...).
1.3 Verify Subdomain Setup
- Ensure the subdomain (e.g.,
store.yoursite.com) is live with the same WooCommerce categories and URL structure. - Test a sample URL:
https://store.yoursite.com/product-category/firefighter-bags/mask-bags/.
Step 2: Redirect Using the Redirection Plugin (No Code)
2.1 Install the Redirection Plugin
- On your old WordPress site (main domain), go to Plugins > Add New.
- Search for Redirection, install, and activate it.
2.2 Create a Wildcard Redirect Rule
- Go to Tools > Redirection.
- Click Add New under the “Redirects” tab.
- Configure the rule:
- Source URL:
^/product-category/(.*)$
(Check the “Regex” box to enable regular expressions). - Target URL:
https://store.yoursite.com/product-category/$1. - Group: Default.
- HTTP Code:
301 - Moved Permanently.
- Source URL:
- Click Add Redirect.

2.3 Test the Redirect
- Visit an old URL in your browser (e.g.,
https://yoursite.com/product-category/firefighter-bags/mask-bags/). - It should redirect to
https://store.yoursite.com/product-category/firefighter-bags/mask-bags/with a 301 status code. - Use Redirect Checker to confirm.
Step 3: Advanced Redirects (Optional)
3.1 Handle Case Sensitivity
- If your old URLs have uppercase letters (e.g.,
Firefighter-Bags), modify the regex to:- Source URL:
^(?i)/product-category/(.*)$
(The(?i)makes it case-insensitive).
- Source URL:
3.2 Redirect URLs with Query Parameters
- Update the regex to include parameters like
?color=red:- Source URL:
^/product-category/(.*)(\?.*)?$ - Target URL:
https://store.yoursite.com/product-category/$1$2.
- Source URL:
Step 4: Server-Level Redirects (Advanced Users)
Use this method if you prefer editing .htaccess for better performance.
4.1 Access Your .htaccess File
- Connect to your server via FTP (e.g., FileZilla) or cPanel File Manager.
- Locate the
.htaccessfile in the root directory of your old site.
4.2 Add Redirect Rules
- Open
.htaccessin a text editor. - Add these rules above the WordPress block (
# BEGIN WordPress):# Redirect all product categories to subdomain RewriteEngine On RewriteRule ^product-category/(.*) https://store.yoursite.com/product-category/$1 [R=301,L] - Save and upload the file.
4.3 Test Server Redirects
- Use
curlor a browser to test:curl -I https://yoursite.com/product-category/firefighter-bags/mask-bags/ - Look for
HTTP/2 301and the correctLocationheader.
Step 5: Post-Launch SEO Checklist
5.1 Update Internal Links
- Use Better Search Replace on the old site to replace
https://yoursite.com/product-category/withhttps://store.yoursite.com/product-category/in:- Posts/pages.
- Menus.
- Widgets.
5.2 Fix Canonical Tags
- On the subdomain, ensure canonical tags point to the subdomain URLs:
<link rel="canonical" href="https://store.yoursite.com/product-category/firefighter-bags/mask-bags/" /> - Use plugins like Yoast SEO or Rank Math to automate this.
5.3 Submit New Sitemaps
- Generate sitemaps for the subdomain using Yoast SEO or Rank Math.
- Submit to:
- Google Search Console.
- Bing Webmaster Tools.
5.4 Monitor for Errors
- Google Search Console: Check the “Coverage” report for crawl errors.
- Screaming Frog: Crawl both sites to find broken links.
- Redirection Logs: Review redirects under Tools > Redirection > Logs.
Step 6: Troubleshooting
6.1 Redirects Not Working
- Cause: Regex syntax error or conflicting plugins.
- Fix:
- Test regex at Regex101.
- Disable caching plugins temporarily (e.g., WP Rocket, W3 Total Cache).
6.2 Mixed Content Warnings
- Cause: HTTP resources (images, CSS) on the subdomain.
- Fix: Use Really Simple SSL to force HTTPS on the subdomain.
6.3 Duplicate Content
- Cause: Old URLs still accessible.
- Fix: Add
noindextags to the old site or remove deprecated pages.
Final Best Practices
- Keep Redirects Permanent: Use 301s, not 302s.
- Preserve URL Structure: Mirror the old site’s paths on the subdomain.
- Test Everything: Use tools like Screaming Frog to validate redirects.
By following this tutorial, you’ll seamlessly migrate your product categories to a subdomain while preserving SEO rankings and user experience. Let me know if you need further clarification! 🚀
Keep your curiosity going.Explore more WordPress →