The Moz Q&A Forum

    • Forum
    • Questions
    • My Q&A
    • Users
    • Ask the Community

    Welcome to the Q&A Forum

    Browse the forum for helpful insights and fresh discussions about all things SEO.

    1. SEO and Digital Marketing Q&A Forum
    2. Categories
    3. Intermediate & Advanced SEO
    4. Regular Expression / Wildcard Redirect Situation

    Regular Expression / Wildcard Redirect Situation

    Intermediate & Advanced SEO
    2 2 376
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as question
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • NakulGoyal
      NakulGoyal last edited by

      I am dealing with an interesting situation. Here's what's going on:

      Current URLs Example1:
      www.domain.com/red-widgets-cid-1234.html
      www.domain.com/red-widgets-cid-1234-1.html
      www.domain.com/red-widgets-cid-1234-1-1.html

      Canonical on All Above URLs:
      www.domain.com/red-widgets-cid-1234.html

      New URL:
      www.domain.com/red-widgets-cid-4567.html


      Current URLs Example2:
      www.domain.com/red-widgets-cid-1234+10.html
      www.domain.com/red-widgets-cid-1234+10-1.html
      www.domain.com/red-widgets-cid-1234+10-1-1.html

      Canonical on All Above URLs:
      www.domain.com/red-widgets-cid-1234+10.html

      New URL:
      www.domain.com/red-widgets-cid-6789.html

      I want to make sure all variations of the above URL redirect to the new url. What wildcard 301 redirect / regular expression can I use to tackle these ?

      1 Reply Last reply Reply Quote 0
      • MikeTek
        MikeTek last edited by

        Hi Nakul,

        Forgive me if this is too simplistic...

        The following rewrite rules should cover the examples you provided:

        RedirectMatch 301 red-widgets-cid-1234.html http://www.domain.com/red-widgets-cid-4567.html
        RedirectMatch 301 red-widgets-cid-1234- http://www.domain.com/red-widgets-cid-4567.html
        RedirectMatch 301 red-widgets-cid-1234+ http://www.domain.com/red-widgets-cid-6789.html

        We just need to escape the special characters (period, hyphen and plus sign).

        This should cover the examples you provided, and no need for any elaborate RegEx patterns. Of course, if there are variants your example doesn't mention, things could get more complicated. (I'm also assuming here you're on an Apache environment.)

        If I've misunderstood your question or the situation is more complicated than your example demonstrates, let me know.

        Thanks,
        Mike

        1 Reply Last reply Reply Quote 0
        • 1 / 1
        • First post
          Last post
        • Unintentional wildcard 301 Redirect?
          0
          1
          122

        • Domain Authority... http://www.domain.com/ vs. http://domain.com vs. http://domain.com/
          MattAntonino
          MattAntonino
          0
          4
          136

        • Should /node/ URLs be 301 redirect to Clean URLs
          MargaritaS
          MargaritaS
          0
          3
          172

        • URL Redirect: http://www.example.net/ vs. http://www.example.net
          dotfly
          dotfly
          0
          2
          705

        • Redirecting a redirect - thoughts?
          MikeRoberts
          MikeRoberts
          0
          2
          165

        • How do i redirect www.domain.com/ to www.domain.com/index.php
          Dr-Pete
          Dr-Pete
          0
          3
          1.3k

        • How to do a wildcard redirect?
          DRSearchEngOpt
          DRSearchEngOpt
          0
          2
          1.6k

        • WWW vs Non-WWW/Moving a site to a new CMS/Redirect all of the previous URLs
          KeriMorgret
          KeriMorgret
          0
          5
          934

        Get started with Moz Pro!

        Unlock the power of advanced SEO tools and data-driven insights.

        Start my free trial
        Products
        • Moz Pro
        • Moz Local
        • Moz API
        • Moz Data
        • STAT
        • Product Updates
        Moz Solutions
        • SMB Solutions
        • Agency Solutions
        • Enterprise Solutions
        • Digital Marketers
        Free SEO Tools
        • Domain Authority Checker
        • Link Explorer
        • Keyword Explorer
        • Competitive Research
        • Brand Authority Checker
        • Local Citation Checker
        • MozBar Extension
        • MozCast
        Resources
        • Blog
        • SEO Learning Center
        • Help Hub
        • Beginner's Guide to SEO
        • How-to Guides
        • Moz Academy
        • API Docs
        About Moz
        • About
        • Team
        • Careers
        • Contact
        Why Moz
        • Case Studies
        • Testimonials
        Get Involved
        • Become an Affiliate
        • MozCon
        • Webinars
        • Practical Marketer Series
        • MozPod
        Connect with us

        Contact the Help team

        Join our newsletter
        Moz logo
        © 2021 - 2026 SEOMoz, Inc., a Ziff Davis company. All rights reserved. Moz is a registered trademark of SEOMoz, Inc.
        • Accessibility
        • Terms of Use
        • Privacy