fervor [>]CODING & CURIOSITY
FERVOR LEARNING SYSTEMTUTORIALS
← WordPress

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

  1. Access to your WordPress dashboard (old site and subdomain).
  2. Redirection Plugin (free).
  3. A spreadsheet tool (Excel/Google Sheets) to map URLs.
  4. FTP access (optional, for .htaccess method).

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

  1. Go to Tools > Redirection.
  2. Click Add New under the “Redirects” tab.
  3. 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.
  4. Click Add Redirect.

Redirection Plugin Example

2.3 Test the Redirect

  1. Visit an old URL in your browser (e.g., https://yoursite.com/product-category/firefighter-bags/mask-bags/).
  2. It should redirect to https://store.yoursite.com/product-category/firefighter-bags/mask-bags/ with a 301 status code.
  3. 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).

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.

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 .htaccess file in the root directory of your old site.

4.2 Add Redirect Rules

  1. Open .htaccess in a text editor.
  2. 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]
    
  3. Save and upload the file.

4.3 Test Server Redirects

  • Use curl or a browser to test:
    curl -I https://yoursite.com/product-category/firefighter-bags/mask-bags/
    
  • Look for HTTP/2 301 and the correct Location header.

Step 5: Post-Launch SEO Checklist

  • Use Better Search Replace on the old site to replace https://yoursite.com/product-category/ with https://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

  1. Generate sitemaps for the subdomain using Yoast SEO or Rank Math.
  2. 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 noindex tags to the old site or remove deprecated pages.

Final Best Practices

  1. Keep Redirects Permanent: Use 301s, not 302s.
  2. Preserve URL Structure: Mirror the old site’s paths on the subdomain.
  3. 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 →
287 TUTORIALS · 22 TOPICSREADY