Need to block subdomain using robots.txt which is on same directory level
Asked Answered
A

3

9

I have one problem

I have domain name for example www.testing.com and new.testing.com so i do not want to new.testing.com display in any search engine. I have added one robots.txt to the new.testing.com. And both site has same parent directory

--httpdoc
----testing.com
----new.testing.com

So i want to know that can i handle both site using one robots.txt of testing.com is it possible???

Please suggest me solution if possible.

Amontillado answered 19/9, 2014 at 7:58 Comment(0)
B
11

The best thing you could do is to add separate robots.txt files. Put one in each directory. You should have

  • testing.com/robots.txt and
  • new.testing.com/robots.txt

After adding robots.txt file to new.testing.com, you should add following code to keep search engines away.

User-agent: *
Disallow: /
Bacciferous answered 19/9, 2014 at 8:21 Comment(1)
if domain and subdomain same directory how can disallow only subdomain? disallow: /new.domain.com/ that true? or have any another idea? please help...Ahimsa
U
6
RewriteEngine on
RewriteCond %{HTTP_HOST} ^subdomain.website.com$
RewriteRule ^robots\.txt$ robots-subdomain.txt

Then add the following to /robots-subdomain.txt:

User-agent: *
Disallow: / 
Uncut answered 2/6, 2015 at 14:53 Comment(0)
O
0

Following rules inside works for me,

RewriteEngine On
RewriteCond %{HTTP_HOST} ^subdomain\.maindomain\.com$ [NC]
RewriteRule ^/robots.txt$ /nobots.txt [L]

And add 'nobots.txt' to root directory as follows,

User-agent: *
Disallow: / 
Okay answered 9/7, 2018 at 13:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.