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

                      • joshibhargav_20

                        Using a Reverse Proxy and 301 redirect to appear Sub Domain as Sub Directory - what are the SEO Risks?

                        We’re in process to move WordPress blog URLs from subdomains to sub-directory. We aren’t moving blog physically, but using reverse proxy and 301 redirection to do this. Blog subdomain URL is https://blog.example.com/ and destination sub-directory URL is https://www.example.com/blog/ Our main website is e-commerce marketplace which is YMYL site. This is on Windows server. Due to technical reasons, we can’t physically move our WordPress blog to the main website. Following is our Technical Setup Setup a reverse proxy at https://www.example.com/blog/ pointing to https://blog.example.com/ Use a 301 redirection from https://blog.example.com/ to https://www.example.com/blog/ with an exception if a traffic is coming from main WWW domain then it won’t redirect. Thus, we can eliminate infinite loop. Change all absolute URLs to relative URLs on blog Change the sitemap URL from https://blog.example.com/sitemap.xml to https://www.example.com/blog/sitemap.xml and update all URLs mentioned within the sitemap. SEO Risk Evaluation We have individual GA Tracking ID and individual Google Search Console Properties for main website and blog. We will not merge them. Keep them separate as they are. Keeping this in mind, I am evaluating SEO Risks factors Right now when we receive traffic from main website to blog (or vice versa) then it is considered as referral traffic and new cookies are set for Google Analytics. What’s going to happen when its on the same domain? Which type of settings change should I do in Blog’s Google Search Console? (A). Do I need to request “Change of Address” in the Blog’s search console property? (B). Should I re-submit the sitemap? Do I need to re-submit the blog sitemap from the https://www.example.com/ Google Search Console Property? Main website is e-commerce marketplace which is YMYL website, and blog is all about content. So does that impact SEO? Will this dilute SEO link juice or impact on the main website ranking because following are the key SEO Metrices. (A). Main website’s Avg Session Duration is about 10 minutes and bounce rate is around 30% (B). Blog’s Avg Session Duration is 33 seconds and bounce rate is over 92%

                        Intermediate & Advanced SEO | Mar 19, 2020, 4:50 PM | joshibhargav_20
                        0
                      • webrocket

                        How do I know if I am correctly solving an uppercase url issue that may be affecting Googlebot?

                        We have a large e-commerce site (10k+ SKUs). https://www.flagandbanner.com. As I have begun analyzing how to improve it I have discovered that we have thousands of urls that have uppercase characters. For instance: https://www.flagandbanner.com/Products/patriotic-paper-lanterns-string-lights.asp. This is inconsistently applied throughout the site. I directed our website vendor to fix the issue and they placed 301 redirects via a rule to the web.config file. Any url that contains an uppercase character now displays as a lowercase. However, as I use screaming frog to monitor our site, I see all these 301 redirects--thousands of them. The XML sitemap still shows the the uppercase versions. We have had indexing issues as well. So I'm wondering what is the most effective way to make sure that I'm not placing an extra burden on Googlebot when they index our site? Should I have just not cared about the uppercase issue and let it alone?

                        Intermediate & Advanced SEO | Nov 30, 2017, 7:26 PM | webrocket
                        0
                      • vtmoz

                        Linking from & to in domains and sub-domains

                        What's the best optimised linking between sub-domains and domains? And every time we'll give website link at top with logo...do we need to link sub-domain also with all it's pages? If example.com is domain and example.com/blog is sub-domain or sub-folder... Do we need to link to example.com from /blog? Do we need to give /blog link in all pages of /blog? Is there any difference in connecting domains with sub-domains and sub-folders?

                        Intermediate & Advanced SEO | Nov 17, 2016, 2:45 PM | vtmoz
                        0
                      • JAR897

                        Keywords in URL: sub-directory or single layer keywords?

                        Hi guys, im putting together a proposal for a new site and trying to figure out if it'd be better to (A) have a keyword split across multiple directories or duplicate keywords to have the keyword hyphenated? For example, for the topic of "Christmas decor" would you use; (A) - www.domain.com/Christmas/Decor (B) - www.domain.com/Christmas/Christmas-Decor in example B the phrase 'Christmas' is duplicated which looks a little spammy, but the key term "Christmas decor" is in the URL without being broken up by directories. which is stronger? Any advice welcome! Thanks guys!

                        Intermediate & Advanced SEO | Apr 8, 2016, 4:48 PM | JAR897
                        1
                      • Waismann

                        Different Header on Home Page vs Sub pages

                        Hello, I am an SEO/PPC manager for a company that does a medical detox. You can see the site in question here: http://opiates.com. My question is, I've never heard of it specifically being a problem to have a different header on the home page of the site than on the subpages, but I rarely see it either. Most sites, if i'm not mistaken, use a consistent header across most of the site. However, a person i'm working for now said that she has had other SEO's look at the site (above) and they always say that it is a big SEO problem to have a different header on the homepage than on the subpages. Any thoughts on this subject? I've never heard of this before. Thanks, Jesse

                        Intermediate & Advanced SEO | Jun 19, 2014, 12:23 PM | Waismann
                        0
                      • workathomecareers

                        Should comments and feeds be disallowed in robots.txt?

                        Hi My robots file is currently set up as listed below. From an SEO point of view is it good to disallow feeds, rss and comments? I feel allowing comments would be a good thing because it's new content that may rank in the search engines as the comments left on my blog often refer to questions or companies folks are searching for more information on. And the comments are added regularly. What's your take? I'm also concerned about the /page being blocked. Not sure how that benefits my blog from an SEO point of view as well. Look forward to your feedback. Thanks. Eddy User-agent: Googlebot Crawl-delay: 10 Allow: /* User-agent: * Crawl-delay: 10 Disallow: /wp- Disallow: /feed/ Disallow: /trackback/ Disallow: /rss/ Disallow: /comments/feed/ Disallow: /page/ Disallow: /date/ Disallow: /comments/ # Allow Everything Allow: /*

                        Intermediate & Advanced SEO | Nov 4, 2013, 9:18 PM | workathomecareers
                        0
                      • Modi

                        Robots Disallow Backslash - Is it right command

                        Bit skeptical, as due to dynamic url and some other linkage issue, google has crawled url with backslash and asterisk character ex - www.xyz.com/\/index.php?option=com_product www.xyz.com/\"/index.php?option=com_product Now %5c is the encoded version of \ - backslash & %22 is encoded version of asterisk Need to know for command :- User-agent: *   Disallow: \As am disallowing all backslash url through this - will it only remove the backslash url which are duplicates or the entire site,

                        Intermediate & Advanced SEO | Jun 24, 2013, 11:38 PM | Modi
                        0
                      • kylesuss

                        Block an entire subdomain with robots.txt?

                        Is it possible to block an entire subdomain with robots.txt? I write for a blog that has their root domain as well as a subdomain pointing to the exact same IP. Getting rid of the option is not an option so I'd like to explore other options to avoid duplicate content. Any ideas?

                        Intermediate & Advanced SEO | Sep 2, 2011, 12:28 PM | kylesuss
                        12

                      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.