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. Block all but one URL in a directory using robots.txt?

    Block all but one URL in a directory using robots.txt?

    Intermediate & Advanced SEO
    3 3 3.5k
    • 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.
    • nicole.healthline
      nicole.healthline last edited by

      Is it possible to block all but one URL with robots.txt?

      for example domain.com/subfolder/example.html, if we block the /subfolder/ directory we want all URLs except for the exact match url domain.com/subfolder to be blocked.

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

        According to my knowledge this possibility does not exist. One fast method to get over this is to get a crawler program to crawl your urls, so that you can quickly copy out all url in the folder paste in in the robots.txt and leave aout the one that you want in the index.

        1 Reply Last reply Reply Quote 0
        • Cyrus-Shepard
          Cyrus-Shepard last edited by

          Robots.txt files are sequential, which means they follow directives in the order they appear. So if two directives conflict, they will follow the last one.

          So the simple way to do this is to disallow all files first, then allow the directory you want next. It would look something like this:

          User-agent: *
          Disallow: /

          User-agent: *
          Allow: /test

          Caveat: This is NOT the way robots.txt is supposed to work. By design, robots.txt is designed for disallowing, and technically you shouldn't ever have to use it for allowing. That said, this should work pretty well.

          You can check your work in Google Webmaster, which has a robots.txt checker. Site Configuration > Crawler Access. Just type in your proposed robots.txt, then a test URL and you should be good to go.

          Hope this helps!

          1 Reply Last reply Reply Quote 2
          • 1 / 1
          • First post
            Last post
          • Block session id URLs with robots.txt
            Mat_C
            Mat_C
            1
            4
            130

          • Block subdomain directory in robots.txt
            DirkC
            DirkC
            0
            5
            1.1k

          • Block in robots.txt instead of using canonical?
            RobertFisher
            RobertFisher
            0
            9
            1.6k

          • Avoiding Duplicate Content with Used Car Listings Database: Robots.txt vs Noindex vs Hash URLs (Help!)
            Everett
            Everett
            0
            10
            2.0k

          • Google showing high volume of URLs blocked by robots.txt in in index-should we be concerned?
            TakeshiYoung
            TakeshiYoung
            0
            4
            302

          • Can URLs blocked with robots.txt hurt your site?
            workzentre
            workzentre
            0
            4
            302

          • Will blocking urls in robots.txt void out any backlink benefits? - I'll explain...
            AubieJon
            AubieJon
            0
            4
            1.0k

          • Blocking Dynamic URLs with Robots.txt
            TaitLarson
            TaitLarson
            1
            4
            5.1k

          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