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. Online Marketing Tools
    4. Advanced Regex Question for URL Matching

    Advanced Regex Question for URL Matching

    Online Marketing Tools
    4 3 178
    • 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.
    • xerox432
      xerox432 last edited by

      Hi,

      I have a website that has numerous 'versions' of the homepage (I know this is an issue with duplicate content - that's separate to this and we are working on that).

      I need to write a regular expression that matches all the following versions of the homepage:

      • http://www.mysite.com
      • http://www.mysite.com/
      • http://www.mysite.com/default.aspx
      • http://www.mysite.com/Default.aspx
      • https://www.mysite.com
      • https://www.mysite.com/
      • https://www.mysite.com/default.aspx
      • https://www.mysite.com/Default.aspx

      At the same time, it needs to **not **match other pages on the site, such as http://www.mysite.com/page1.

      How would I write this?

      Thanks,

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

        I'm not sure what context you're using this in but this should do the trick (works with PCRE)

        ^http://www.mysite.com(?:/|)(?:[D,d]efault.aspx|)$

        xerox432 1 Reply Last reply Reply Quote 0
        • TheeDigital
          TheeDigital last edited by

          I think you should look into the DirectoryIndex directive instead.

          1 Reply Last reply Reply Quote 0
          • xerox432
            xerox432 @Highland last edited by

            Hi,

            Thanks for the response. It's for Google Tag Manager.

            In the end we had to set it up thus:

            (https?://www.mysite.com/default.aspx)|(https?://www.mysite.com/?$)

            GTM has an option to let you ignore case in the regex. For some reason, it didn't work if we swapped the two URLs either side of the pipe around.

            Thanks!

            1 Reply Last reply Reply Quote 0
            • 1 / 1
            • First post
              Last post
            • Do you canonicalise UTM URLs?
              Eric_S
              Eric_S
              0
              15
              1.7k

            • Search Analytics Question
              MichaelC-15022
              MichaelC-15022
              0
              5
              132

            • Url grabber?
              Travis_Bailey
              Travis_Bailey
              0
              5
              1.4k

            • Question on Google analytics
              danatanseo
              danatanseo
              0
              5
              422

            • Question Redacted
              DJ123
              DJ123
              0
              3
              112

            • Facebook ad matching
              Martijn_Scheijbeler
              Martijn_Scheijbeler
              1
              2
              139

            • Feedburner email subscription question
              rmontanez
              rmontanez
              0
              2
              334

            • Advanced marketing strategies
              JamesNorquay
              JamesNorquay
              0
              2
              774

            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