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.
    • 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
                            • I am looking for best way to block a domain from getting indexed ?
                              Prasadgotteti
                              Prasadgotteti
                              0
                              5
                              90

                            • 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

                            • Blog.domain or domain.com/blog
                              Asjad
                              Asjad
                              0
                              7
                              206

                            • Correct linking to the /index of a site and subfolders: what's the best practice? link to: domain.com/ or domain.com/index.html ?
                              CleverPhD
                              CleverPhD
                              0
                              4
                              245

                            • How best to deal with www.home.com and www.home.com/index.html
                              Creatomatic
                              Creatomatic
                              0
                              6
                              315

                            • To 301 redirect or not to 301 redirect? duplicate content problem www.domain.com and www.domain.com/en/
                              Chris-CA
                              Chris-CA
                              0
                              5
                              456

                            • 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