undefined
Skip to content
Moz logo Menu open Menu close
  • Products
    • Moz Pro
    • Moz Pro Home
    • Moz Local
    • Moz Local Home
    • STAT
    • Moz API
    • Moz API Home
    • Compare SEO Products
    • Moz Data
  • Free SEO Tools
    • Domain Analysis
    • Keyword Explorer
    • Link Explorer
    • Competitive Research
    • MozBar
    • More Free SEO Tools
  • Learn SEO
    • Beginner's Guide to SEO
    • SEO Learning Center
    • Moz Academy
    • MozCon
    • Webinars, Whitepapers, & Guides
  • Blog
  • Why Moz
    • Digital Marketers
    • Agency Solutions
    • Enterprise Solutions
    • Small Business Solutions
    • The Moz Story
    • New Releases
  • Log in
  • Log out
  • Products
    • Moz Pro

      Your all-in-one suite of SEO essentials.

    • Moz Local

      Raise your local SEO visibility with complete local SEO management.

    • STAT

      SERP tracking and analytics for enterprise SEO experts.

    • Moz API

      Power your SEO with our index of over 44 trillion links.

    • Compare SEO Products

      See which Moz SEO solution best meets your business needs.

    • Moz Data

      Power your SEO strategy & AI models with custom data solutions.

    Track AI Overviews in Keyword Research
    Moz Pro

    Track AI Overviews in Keyword Research

    Try it free!
  • Free SEO Tools
    • Domain Analysis

      Get top competitive SEO metrics like DA, top pages and more.

    • Keyword Explorer

      Find traffic-driving keywords with our 1.25 billion+ keyword index.

    • Link Explorer

      Explore over 40 trillion links for powerful backlink data.

    • Competitive Research

      Uncover valuable insights on your organic search competitors.

    • MozBar

      See top SEO metrics for free as you browse the web.

    • More Free SEO Tools

      Explore all the free SEO tools Moz has to offer.

    NEW Keyword Suggestions by Topic
    Moz Pro

    NEW Keyword Suggestions by Topic

    Learn more
  • Learn SEO
    • Beginner's Guide to SEO

      The #1 most popular introduction to SEO, trusted by millions.

    • SEO Learning Center

      Broaden your knowledge with SEO resources for all skill levels.

    • On-Demand Webinars

      Learn modern SEO best practices from industry experts.

    • How-To Guides

      Step-by-step guides to search success from the authority on SEO.

    • Moz Academy

      Upskill and get certified with on-demand courses & certifications.

    • MozCon

      Save on Early Bird tickets and join us in London or New York City

    Unlock flexible pricing & new endpoints
    Moz API

    Unlock flexible pricing & new endpoints

    Find your plan
  • Blog
  • Why Moz
    • Digital Marketers

      Simplify SEO tasks to save time and grow your traffic.

    • Small Business Solutions

      Uncover insights to make smarter marketing decisions in less time.

    • Agency Solutions

      Earn & keep valuable clients with unparalleled data & insights.

    • Enterprise Solutions

      Gain a competitive edge in the ever-changing world of search.

    • The Moz Story

      Moz was the first & remains the most trusted SEO company.

    • New Releases

      Get the scoop on the latest and greatest from Moz.

    Surface actionable competitive intel
    New Feature

    Surface actionable competitive intel

    Learn More
  • Log in
    • Moz Pro
    • Moz Local
    • Moz Local Dashboard
    • Moz API
    • Moz API Dashboard
    • Moz Academy
  • Avatar
    • Moz Home
    • Notifications
    • Account & Billing
    • Manage Users
    • Community Profile
    • My Q&A
    • My Videos
    • Log Out

The Moz Q&A Forum

  • Forum
  • Questions
  • Users
  • Ask the Community

Welcome to the Q&A Forum

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

  1. Home
  2. SEO Tactics
  3. Intermediate & Advanced SEO
  4. Robots.txt: how to exclude sub-directories correctly?

Moz Q&A is closed.

After more than 13 years, and tens of thousands of questions, Moz Q&A closed on 12th December 2024. Whilst we’re not completely removing the content - many posts will still be possible to view - we have locked both new posts and new replies. More details here.

Robots.txt: how to exclude sub-directories correctly?

Intermediate & Advanced SEO
3
10
53.1k
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as question
Log in to reply
This topic has been deleted. Only users with question management privileges can see it.
  • fablau
    fablau last edited by Dec 13, 2013, 3:42 PM

    Hello here,

    I am trying to figure out the correct way to tell SEs to crawls this:

    http://www.mysite.com/directory/

    But not this:

    http://www.mysite.com/directory/sub-directory/

    or this:

    http://www.mysite.com/directory/sub-directory2/sub-directory/...

    But with the fact I have thousands of sub-directories with almost infinite combinations, I can't put the following definitions in a manageable way:

    disallow: /directory/sub-directory/

    disallow: /directory/sub-directory2/

    disallow: /directory/sub-directory/sub-directory/

    disallow: /directory/sub-directory2/subdirectory/

    etc...

    I would end up having thousands of definitions to disallow all the possible sub-directory combinations.

    So, is the following way a correct, better and shorter way to define what I want above:

    allow: /directory/$

    disallow: /directory/*

    Would the above work?

    Any thoughts are very welcome! Thank you in advance.

    Best,

    Fab.

    1 Reply Last reply Reply Quote 1
    • MickEdwards
      MickEdwards @sjunaidali last edited by Nov 10, 2017, 5:46 AM Nov 10, 2017, 5:46 AM

      I mentioned both.  You add a meta robots to noindex and remove from the sitemap.

      1 Reply Last reply Reply Quote 0
      • sjunaidali
        sjunaidali @MickEdwards last edited by Nov 10, 2017, 5:13 AM Nov 10, 2017, 5:13 AM

        But google is still free to index a link/page even if it is not included in xml sitemap.

        MickEdwards 1 Reply Last reply Nov 10, 2017, 5:46 AM Reply Quote 0
        • MickEdwards
          MickEdwards @sjunaidali last edited by Nov 9, 2017, 12:34 PM Nov 9, 2017, 12:34 PM

          Install Yoast Wordpress SEO plugin and use that to restrict what is indexed and what is allowed in a sitemap.

          sjunaidali 1 Reply Last reply Nov 10, 2017, 5:13 AM Reply Quote 1
          • sjunaidali
            sjunaidali @MickEdwards last edited by Nov 9, 2017, 11:54 AM Nov 9, 2017, 11:54 AM

            I am using wordpress, Enfold theme (themeforest).

            I want some files to be accessed by google, but those should not be indexed.

            Here is an example: http://prntscr.com/h8918o

            I have currently blocked some JS directories/files using robots.txt (check screenshot)

            But due to this I am not able to pass Mobile Friendly Test on Google: http://prntscr.com/h8925z (check screenshot)

            Is its possible to allow access, but use a tag like noindex in the robots.txt file. Or is there any other way out.

            MickEdwards 1 Reply Last reply Nov 9, 2017, 12:34 PM Reply Quote 0
            • topic:timeago_earlier,4 years
            • fablau
              fablau last edited by Apr 11, 2019, 3:24 PM Dec 16, 2013, 7:25 PM

              Yes, everything looks good, Webmaster Tools gave me the expected results with the following directives:

              allow: /directory/$

              disallow: /directory/*

              Which allows this URL:

              http://www.mysite.com/directory/

              But doesn't allow the following one:

              http://www.mysite.com/directory/sub-directory2/...

              This page also gives an update similar to mine:

              https://support.google.com/webmasters/answer/156449?hl=en

              I think I am good! Thanks 🙂

              1 Reply Last reply Reply Quote 2
              • fablau
                fablau last edited by Dec 16, 2013, 3:46 PM Dec 16, 2013, 3:46 PM

                Thank you Michael, it is my understanding then that my idea of doing this:

                allow: /directory/$

                disallow: /directory/*

                Should work just fine. I will test it within Google Webmaster Tools, and let you know if any problems arise.

                In the meantime if anyone else has more ideas about all this and can confirm me that would be great!

                Thank you again.

                1 Reply Last reply Reply Quote 1
                • MickEdwards
                  MickEdwards @fablau last edited by Dec 16, 2013, 7:26 PM Dec 14, 2013, 5:08 AM

                  I've always stuck to Disallow and followed -

                  "This is currently a bit awkward, as there is no "Allow" field. The easy way is to put all files to be disallowed into a separate directory, say "stuff", and leave the one file in the level above this directory:"

                  http://www.robotstxt.org/robotstxt.html

                  From https://developers.google.com/webmasters/control-crawl-index/docs/robots_txt this seems contradictory

                  | /* | equivalent to / | equivalent to / | Equivalent to "/" -- the trailing wildcard is ignored. |

                  I think this post will be very useful  for you - http://moz.com/community/q/allow-or-disallow-first-in-robots-txt

                  1 Reply Last reply Reply Quote 1
                  • fablau
                    fablau @MickEdwards last edited by Dec 13, 2013, 7:05 PM Dec 13, 2013, 7:05 PM

                    Thank you Michael,

                    Google and other SEs actually recognize the "allow:" command:

                    https://developers.google.com/webmasters/control-crawl-index/docs/robots_txt

                    The fact is: if I don't specify that, how can I be sure that the following single command:

                    disallow: /directory/*

                    Doesn't prevent SEs to spider the /directory/ index as I'd like to?

                    MickEdwards 1 Reply Last reply Dec 14, 2013, 5:08 AM Reply Quote 0
                    • MickEdwards
                      MickEdwards last edited by Dec 13, 2013, 4:59 PM Dec 13, 2013, 4:58 PM

                      As long as you dont have directories somewhere in /* that you want indexed then I think that will work.  There is no allow so you don't need the first line just

                      disallow: /directory/*

                      You can test out here- https://support.google.com/webmasters/answer/156449?rd=1

                      fablau sjunaidali 2 Replies Last reply Nov 9, 2017, 11:54 AM Reply Quote 0
                      • 1 / 1
                      1 out of 10
                      • First post
                        1/10
                        Last post

                      Got a burning SEO question?

                      Subscribe to Moz Pro to gain full access to Q&A, answer questions, and ask your own.


                      Start my free trial


                      Browse Questions

                      Explore more categories

                      • Moz Tools

                        Chat with the community about the Moz tools.

                      • SEO Tactics

                        Discuss the SEO process with fellow marketers

                      • Community

                        Discuss industry events, jobs, and news!

                      • Digital Marketing

                        Chat about tactics outside of SEO

                      • Research & Trends

                        Dive into research and trends in the search industry.

                      • Support

                        Connect on product support and feature requests.

                      • See all categories

                      Related Questions

                      • Kingalan1

                        H1 and Schema Codes Set Up Correctly?

                        Greetings: It was pointed out to me that the h1 tags on my website (www.nyc-officespace-leader.com) all had exactly the same text and that duplication may be contributing to the very low page authority for most URLs. The duplicate h1 appears in line 54-54 (see below) of the home page: www.nyc-officespace-leader.com: itemscope itemtype="http://schema.org/LocalBusiness" style="position:absolute;top:-9999em;"> <span<br>itemprop="name">Metro Manhattan Office Space</span<br> <img< p="">But the above refers to schema" so is this really duplicate H1 or is there an exception if the H1 is within a schema? Also, I was told that the company street address and city and state were set up incorrectly as part of an alt tag. However these items also appear as schema in lines 49-68 shown below: Dangerous for me to perform surgery on the code without being certain about these key items!! Could ask my developer, however they may be uncomfortable considering that they set this up in the 1st place. So the view of neutral professionals would be highly welcome! itemprop="address" itemscope itemtype="http://schema.org/PostalAddress">
                        <span<br>itemprop="streetAddress">347 5th Ave #1008
                        <span<br>itemprop="addressLocality">New York
                        <span<br>itemprop="addressRegion">NY
                        <span<br>itemprop="postalCode">10016<div<br>itemprop="brand" itemscope itemtype="http://schema.org/Organization">
                        ---------------------------------------------------------------------------</div<br></span<br></span<br></span<br></span<br></img<>

                        Intermediate & Advanced SEO | Dec 27, 2017, 7:04 PM | Kingalan1
                        0
                      • Tylerj

                        Should I use noindex or robots to remove pages from the Google index?

                        I have a Magento site and just realized we have about 800 review pages indexed. The /review directory is disallowed in robots.txt but the pages are still indexed. From my understanding robots means it will not crawl the pages BUT if the pages are still indexed if they are linked from somewhere else. I can add the noindex tag to the review pages but they wont be crawled. https://www.seroundtable.com/google-do-not-use-noindex-in-robots-txt-20873.html Should I remove the robots.txt and add the noindex? Or just add the noindex to what I already have?

                        Intermediate & Advanced SEO | Feb 28, 2017, 12:24 PM | Tylerj
                        0
                      • NortonSupportSEO

                        Is it possible to have organization markup schema for sub domain ? and how should it look like ?

                        Can we have organization markup schema for subdomain ? For example if my main domain is xyz.com and subdomain is sub.xyz.com If i plan to have organization markup schema for subdomain how should it look like ? Should the markup schema must have main domain url or sub domain url in markup schema ? Should it be like this ?

                        Intermediate & Advanced SEO | Mar 1, 2017, 4:16 PM | NortonSupportSEO
                        0
                      • Gabriele_Layoutweb

                        If I block a URL via the robots.txt - how long will it take for Google to stop indexing that URL?

                        If I block a URL via the robots.txt - how long will it take for Google to stop indexing that URL?

                        Intermediate & Advanced SEO | Jan 31, 2017, 9:06 PM | Gabriele_Layoutweb
                        0
                      • danatanseo

                        How is Google crawling and indexing this directory listing?

                        We have three Directory Listing pages that are being indexed by Google: http://www.ccisolutions.com/StoreFront/jsp/ http://www.ccisolutions.com/StoreFront/jsp/html/ http://www.ccisolutions.com/StoreFront/jsp/pdf/ How and why is Googlebot crawling and indexing these pages? Nothing else links to them (although the /jsp.html/ and /jsp/pdf/ both link back to /jsp/). They aren't disallowed in our robots.txt file and I understand that this could be why. If we add them to our robots.txt file and disallow, will this prevent Googlebot from crawling and indexing those Directory Listing pages without prohibiting them from crawling and indexing the content that resides there which is used to populate pages on our site? Having these pages indexed in Google is causing a myriad of issues, not the least of which is duplicate content. For example, this file <tt>CCI-SALES-STAFF.HTML</tt> (which appears on this Directory Listing referenced above - http://www.ccisolutions.com/StoreFront/jsp/html/) clicks through to this Web page: http://www.ccisolutions.com/StoreFront/jsp/html/CCI-SALES-STAFF.HTML This page is indexed in Google and we don't want it to be. But so is the actual page where we intended the content contained in that file to display: http://www.ccisolutions.com/StoreFront/category/meet-our-sales-staff As you can see, this results in duplicate content problems. Is there a way to disallow Googlebot from crawling that Directory Listing page, and, provided that we have this URL in our sitemap: http://www.ccisolutions.com/StoreFront/category/meet-our-sales-staff, solve the duplicate content issue as a result? For example: Disallow: /StoreFront/jsp/ Disallow: /StoreFront/jsp/html/ Disallow: /StoreFront/jsp/pdf/ Can we do this without risking blocking Googlebot from content we do want crawled and indexed? Many thanks in advance for any and all help on this one!

                        Intermediate & Advanced SEO | Sep 13, 2013, 6:49 PM | danatanseo
                        0
                      • rahul11

                        How to do geo targeting for domain and sub directories in Webmaster tool?

                        Hello All, How can i do geo targeting in multiple countries on my ** root domain and sub **directories in Webmaster tool. My domain is "abc.com" and i want to target three countries UAE , Kuwait, Saudi arabia. So, Can i assign geo targeting in Webmaster tool ,  Root domain for UAE country and make other two sub directories for Kuwait and saudi ? abc.com - UAE (geo targeting) abc.com/kw - Kuwait (geo targeting) abc.com/sa - Saudi  (geo targeting) Or Root doamain should be not assign for any country and Make three sub directories for UAE, Kuwait , and saudi and targeting them there geo locations. abc.com - Unlisted (geo targeting) abc.com/uae/ - UAE (geo targeting) abc.com/kw/ - Kuwait (geo targeting) abc.com/sa/ - Saudi  (geo targeting)

                        Intermediate & Advanced SEO | Mar 24, 2013, 9:09 PM | rahul11
                        0
                      • seo123456

                        Using 2 wildcards in the robots.txt file

                        I have a URL string which I don't want to be indexed. it includes the characters _Q1 ni the middle of the string. So in the robots.txt can I use 2 wildcards in the string to take out all of the URLs with that in it?  So something like /_Q1.  Will that pickup and block every  URL with those characters in the string? Also, this is not directly of the root, but in a secondary directory, so .com/.../_Q1.  So do I have to format the robots.txt as //_Q1* as it will be in the second folder or just using /_Q1 will pickup everything no matter what folder it is on? Thanks.

                        Intermediate & Advanced SEO | Jan 20, 2012, 5:25 AM | seo123456
                        0
                      • TECHeGO

                        Getting Google to Correct a Misspelled Site Link...Help!

                        My company website recently got its site links in google search... WooHoo! However, when you type TECHeGO into Google Search one of the links is spelled incorrectly. Instead of 'CONversion Optimization' its 'COversion Optimization'. At first I thought there was a misspelling on that page somewhere but there is not and have come to the conclusion that Google has made a mistake. I know that I can block the page in webmaster tools (No Thanks) but how in the crap can I get them to correct the spelling when no one really knows how to get them to appear in the first place? Riddle Me That Folks! sitelink.jpg

                        Intermediate & Advanced SEO | Apr 25, 2011, 2:31 PM | TECHeGO
                        0

                      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 - 2025 SEOMoz, Inc., a Ziff Davis company. All rights reserved. Moz is a registered trademark of SEOMoz, Inc.
                      • Accessibility
                      • Terms of Use
                      • Privacy

                      Looks like your connection to Moz was lost, please wait while we try to reconnect.