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. Technical SEO Issues
    4. What is the best method to block a sub-domain, e.g. staging.domain.com/ from getting indexed?

    What is the best method to block a sub-domain, e.g. staging.domain.com/ from getting indexed?

    Technical SEO Issues
    13 4 6.3k
    • 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.
    • fthead9
      fthead9 last edited by

      Now that Google considers subdomains as part of the TLD I'm a little leery of testing robots.txt with something like:

      staging.domain.com
      User-agent: *
      Disallow: /

      in fear it might get the www.domain.com blocked as well. Has anyone had any success using robots.txt to block sub-domains? I know I could add a meta robots tag to the staging.domain.com pages but that would require a lot more work.

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

        What is the best method to block a sub-domain, e.g. staging.domain.com/ from getting indexed?

        Place a robots.txt file in the root of the subdomain.

        User-agent: *
        Disallow: /

        This method will block the subdomain while leaving your primary domain unaffected.

        fthead9 1 Reply Last reply Reply Quote 2
        • bloggidy
          bloggidy last edited by

          Use an .htaccess file to only allow from certain ip addresses or ranges.

          Here is an article describing how: http://www.kirupa.com/html5/htaccess_tricks.htm

          fthead9 RyanKent 2 Replies Last reply Reply Quote 1
          • fthead9
            fthead9 @RyanKent last edited by

            Thanks Ryan. So you don't see any issues with de-indexing the main site if I created a second robots.txt file, e.g.

            http://staging.domin.com/robots.txt

            User-agent: *
            Disallow: /

            That was my initial thought but when Google announced they consider sub-domains part of the TLD I was afraid it might affect the htp://www.domain.com versions of the pages. So you're saying the subdomain is basically treated like a folder you block on the primary domain?

            RyanKent 1 Reply Last reply Reply Quote 0
            • fthead9
              fthead9 @bloggidy last edited by

              Interesting, hadn't thought of using htaccess to block Googlebot.Thanks for the suggestion.

              RyanKent bloggidy 2 Replies Last reply Reply Quote 0
              • RyanKent
                RyanKent @bloggidy last edited by

                Hi Matt.

                Perhaps I misunderstood the question but I believe Toren only wishes to prevent the subdomain from being indexed. If you restrict subdomain access by IP it would prevent visitors from accessing the content which I don't believe is the goal.

                bloggidy fthead9 RyanKent KeriMorgret 4 Replies Last reply Reply Quote 1
                • RyanKent
                  RyanKent @fthead9 last edited by

                  Toren, I would not recommend that solution. There is nothing to prevent Googlebot from crawling your site via almost any IP. If you found 100 IPs used by the crawler and blocked them all, there is nothing to stop the crawler from using IP #101 next month. Once the subdomain's content is located and indexed, it will be a headache fixing the issue.

                  The best solution is always going to be a noindex meta tag on the pages you do not wish to be indexed. If that method is too much work or otherwise undesirable, you can use the robots.txt solution. There is no circumstance I can imagine where you would modify your htaccess file to block googlebot.

                  1 Reply Last reply Reply Quote 1
                  • RyanKent
                    RyanKent @fthead9 last edited by

                    Correct.

                    1 Reply Last reply Reply Quote 0
                    • bloggidy
                      bloggidy @fthead9 last edited by

                      Staging URL's are typically only used for testing so rather than do a deny I would recommend using a specific ALLOW for only the IP addresses that should be allowed access.

                      I would imagine you don't want it indexed because you don't want the rest of the world knowing about it.

                      You can also use HTACCESS to use username/passwords. It is simple but you can give that to clients if that is a concern/need.

                      1 Reply Last reply Reply Quote 0
                      • bloggidy
                        bloggidy @RyanKent last edited by

                        .htaccess files can be placed at any directory level of a site so you can do it for just the subdomain or even just a directory of a domain.

                        1 Reply Last reply Reply Quote 1
                        • fthead9
                          fthead9 @RyanKent last edited by

                          Matt/Ryan-

                          Great discussion, thanks for the input. The staging.domain.com is just one of the domains we don't want indexed. Some of them still need to be accessed by the public, some like staging could be restricted to specific IPs.

                          I realize after your discussion I probably should have used a different example of a sub-domain. On the other hand it might not have sparked the discussion so maybe it was a good example 😉

                          1 Reply Last reply Reply Quote 0
                          • RyanKent
                            RyanKent @RyanKent last edited by

                            I agree. The name of your subdomain being "staging" didn't register at all with me until Matt brought it up. I was offering a generic response to the subdomain question whereas I believe Matt focused on how to handle a staging site. Interesting viewpoint.

                            1 Reply Last reply Reply Quote 0
                            • KeriMorgret
                              KeriMorgret @RyanKent last edited by

                              Just make sure that when/if you copy over the staging site to the live domain that you don't copy over the robots.txt, htaccess, or whatever means you use to block that site from being indexed and thus have your shiny new site be blocked. 🙂

                              1 Reply Last reply Reply Quote 1
                              • 1 / 1
                              • First post
                                Last post
                              • We switched the domain from www.blog.domain.com to domain.com/blog.
                                Nigel_Carr
                                Nigel_Carr
                                0
                                3
                                170

                              • Google has indexed m.freedomltd.com/hen-nights/party-locations/london//cocktail-training/ missing a folder.
                                GPainter
                                GPainter
                                0
                                5
                                106

                              • Staging & Development areas should be not indexable (i.e. no followed/no index in meta robots etc)
                                CleverPhD
                                CleverPhD
                                0
                                14
                                3.9k

                              • How to prevent duplicat content issue and indexing sub domain [ CDN sub domain]?
                                Dr-Pete
                                Dr-Pete
                                0
                                3
                                328

                              • How best to deal with www.home.com and www.home.com/index.html
                                donford
                                donford
                                0
                                4
                                494

                              • Domain.com and domain.com/ redirect(error)
                                cgman
                                cgman
                                0
                                8
                                757

                              • Getting multiple errors for domain.com/xxxx/xxxx/feed/feed/feed/feed...
                                Brandtailers
                                Brandtailers
                                0
                                5
                                1.4k

                              • I have a site that has both http:// and https:// versions indexed, e.g. https://www.homepage.com/ and http://www.homepage.com/. How do I de-index the https// versions without losing the link juice that is going to the https://homepage.com/ pages?
                                fthead9
                                fthead9
                                0
                                3
                                729

                              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