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.

    NEW Keyword Suggestions by Topic
    Moz Pro

    NEW Keyword Suggestions by Topic

    Learn more
  • 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

                      • Opera-Care

                        Is there any significant benefit to creating online directory listings that only provide nofollow links to our domain?

                        Is there any significant benefit to creating online directory listings that only provide nofollow links to our domain? For context, whilst doing link gap analysis I've found our competitors are listed on local government directories such as getsurrey.co.uk and miltonkeynes.co.uk. Whilst these aren't seen as spam directories, it's still highly unlikely we'll receive much traffic through them. The links they provide to our domain have the nofollow tag. So I wonder whether there's any other benefit to investing the time in creating these listings? Would be interested to hear your thoughts Many thanks in advance

                        Intermediate & Advanced SEO | Nov 18, 2019, 8:34 AM | Opera-Care
                        1
                      • Malika1

                        If Robots.txt have blocked an Image (Image URL) but the other page which can be indexed has this image, how is the image treated?

                        Hi MOZers, This probably is a dumb question but I have a case where the robots.tags has an image url blocked but this image is used on a page (lets call it Page A) which can be indexed. If the image on Page A has an Alt tags, then how is this information digested by crawlers? A) would Google totally ignore the image and the ALT tags information? OR B) Google would consider the ALT tags information? I am asking this because all the images on the website are blocked by robots.txt at the moment but I would really like website crawlers to crawl the alt tags information. Chances are that I will ask the webmaster to allow indexing of images too but I would like to understand what's happening currently. Looking forward to all your responses 🙂 Malika

                        Intermediate & Advanced SEO | Jun 16, 2016, 11:17 AM | Malika1
                        1
                      • digitalcrc

                        Does it hurt your SEO to have an inaccessible directory in your site structure?

                        Due to CMS constraints, there may be some nodes in our site tree that are inaccessible and will automatically redirect to their parent folder. Here's an example: www.site.com/folder1/folder2/content, /folder2 redirects to /folder1. This would only be for the single URL itself, not the subpages (i.e. /folder1/folder2/content and anything below that would be accessible). Is there any real risk in this approach from a technical SEO perspective? I'm thinking this is likely a non-issue but I'm hoping someone with more experience can confirm. Another potential option is to have /folder2 accessible (it would be 100% identical to /folder1, long story) and use a canonical tag to point back to /folder1. I'm still waiting to hear if this is possible. Thanks in advance!

                        Intermediate & Advanced SEO | Aug 25, 2015, 11:24 AM | digitalcrc
                        0
                      • seo.owl

                        How to handle a blog subdomain on the main sitemap and robots file?

                        Hi, I have some confusion about how our blog subdomain is handled in our sitemap.  We have our main website, example.com, and our blog, blog.example.com. Should we list the blog subdomain URL in our main sitemap?  In other words, is listing a subdomain allowed in the root sitemap? What does the final structure look like in terms of the sitemap and robots file?  Specifically: **example.com/sitemap.xml ** would I include a link to our blog subdomain (blog.example.com)? example.com/robots.xml would I include a link to BOTH our main sitemap and blog sitemap? blog.example.com/sitemap.xml would I include a link to our main website URL (even though it's not a subdomain)? blog.example.com/robots.xml does a subdomain need its own robots file? I'm a technical SEO and understand the mechanics of much of on-page SEO.... but for some reason I never found an answer to this specific question and I am wondering how the pros do it.  I appreciate your help with this.

                        Intermediate & Advanced SEO | Oct 21, 2014, 3:35 PM | seo.owl
                        0
                      • YairSpolter

                        Block in robots.txt instead of using canonical?

                        When I use a canonical tag for pages that are variations of the same page, it basically means that I don't want Google to index this page. But at the same time, spiders will go ahead and crawl the page. Isn't this a waste of my crawl budget? Wouldn't it be better to just disallow the page in robots.txt and let Google focus on crawling the pages that I do want indexed? In other words, why should I ever use rel=canonical as opposed to simply disallowing in robots.txt?

                        Intermediate & Advanced SEO | Jul 23, 2014, 11:19 AM | YairSpolter
                        0
                      • Milian

                        Robots.txt, does it need preceding directory structure?

                        Do you need the entire preceding path in robots.txt for it to match? e.g: I know if i add Disallow: /fish to robots.txt it will block /fish
                        /fish.html
                        /fish/salmon.html
                        /fishheads
                        /fishheads/yummy.html
                        /fish.php?id=anything But would it block?: en/fish
                        en/fish.html
                        en/fish/salmon.html
                        en/fishheads
                        en/fishheads/yummy.html
                        **en/fish.php?id=anything (taken from Robots.txt Specifications)** I'm hoping it actually wont match, that way writing this particular robots.txt will be much easier! As basically I'm wanting to block many URL that have BTS- in such as: http://www.example.com/BTS-something
                        http://www.example.com/BTS-somethingelse
                        http://www.example.com/BTS-thingybob But have other pages that I do not want blocked, in subfolders that also have BTS- in, such as: http://www.example.com/somesubfolder/BTS-thingy
                        http://www.example.com/anothersubfolder/BTS-otherthingy Thanks for listening

                        Intermediate & Advanced SEO | Oct 15, 2013, 5:58 AM | Milian
                        0
                      • monster99

                        How to Disallow Tag Pages With Robot.txt

                        Hi i have a site which i'm dealing with that has tag pages for instant - http://www.domain.com/news/?tag=choice How can i exclude these tag pages (about 20+ being crawled and indexed by the search engines with robot.txt Also sometimes they're created dynamically so i want something which automatically excludes tage pages from being crawled and indexed. Any suggestions? Cheers, Mark

                        Intermediate & Advanced SEO | Nov 1, 2012, 11:24 PM | monster99
                        0
                      • SEODinosaur

                        SEOmoz recommended Directories

                        SEOmoz recommends a bunch of directories and some cost money. How much influence do these directories have? Is it worth investing in some where the category makes sense or all where the category makes sense?

                        Intermediate & Advanced SEO | Jun 29, 2012, 12:50 AM | SEODinosaur
                        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
                      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.