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. Can someone help me with RegEx?

    Can someone help me with RegEx?

    Intermediate & Advanced SEO
    6 2 112
    • 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.
    • cyberlicious
      cyberlicious last edited by

      Hey!

      I am having a tough time figuring this out, and I have already signed up for my RegEx course.  So in the mean time, could you please help me?

      I have two old URLs:

      /faq

      /faq.php

      The new one is /faqs

      How can I write a 301 redirect to include faq & faq.php in the same line?  I basically want to capture /faq and anything beyond the q including the .php.

      I thought this would work:

      Redirect 301 /faq. http://www.blah.com/faqs

      Using the period to catch everything after the q and redirect it to the /faqs page.

      Extra credit: And why Redirect 301 vs. RedirectMatch 301?  It is an Apache server and mod_ rewrite is on.

      Thanks in advance!

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

        I'm going to have to do a rule, aren't I?  Basically to include (faq|faq.php) or something like that, huh?  So a RewriteRule is going to have to be used instead of Redirect or RedirectMatch.

        Please help!

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

          RewriteCond %{SCRIPT_FILENAME} !-f
          RewriteCond %{SCRIPT_FILENAME} !-d
          RewriteRule ^faq(.*) /faqs [L,R=301]

          That should do the trick 🙂

          cyberlicious 1 Reply Last reply Reply Quote 1
          • cyberlicious
            cyberlicious @OlegKorneitchouk last edited by

            Thanks Oleg!!!

            -f is for file and -d is for directory, correct?

            I found a 5 hour course on Lynda.com on RegEx so I'll be doing that this evening.

            Thanks again for your quick response.  Much appreciated!!!

            OlegKorneitchouk 1 Reply Last reply Reply Quote 0
            • OlegKorneitchouk
              OlegKorneitchouk @cyberlicious last edited by

              -f is for file and -d is for directory, correct?

              Correct.

              And your very welcome 😄

              A course should help you understand RegEx a lot more but I still find myself looking up specific situations online.

              cyberlicious 1 Reply Last reply Reply Quote 0
              • cyberlicious
                cyberlicious @OlegKorneitchouk last edited by

                Yes, I bet.  I just want to be able to know what I'm asking.  lol

                Thanks again for your help!  🙂

                1 Reply Last reply Reply Quote 0
                • 1 / 1
                • First post
                  Last post
                • My product category pages are not being indexed on google can someone help?
                  effectdigital
                  effectdigital
                  0
                  2
                  492

                • Looking for someone to help with a delisted site after a malicious hack
                  Sallyfgdfh
                  Sallyfgdfh
                  0
                  6
                  116

                • Can anyone help me figure out these sitelinks?
                  DanDeceuster
                  DanDeceuster
                  0
                  5
                  71

                • Can someone help me understand why this page is ranking so well?
                  FPD_NYC
                  FPD_NYC
                  1
                  14
                  200

                • Moving blog to a subdomain, how can I help it rank?
                  DigitalMoz
                  DigitalMoz
                  0
                  13
                  229

                • Title tags seem to be going against Rand and suggestions here, what can I do? Can you help me please?
                  vmialik
                  vmialik
                  0
                  5
                  120

                • I'm having an exteremly hard time with SERPs despite my best efforts. Can someone help?
                  TomRayner
                  TomRayner
                  0
                  4
                  118

                • No results for Yahoo. Can someone fill me in on something I am missing?
                  BTeubner
                  BTeubner
                  0
                  2
                  446

                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