htaccess allow just a specific url for a specific subdomain and disallow all the rest

412 Views Asked by At

We have 2 subdomains for our websites.

  • subdomain1.xxxxx.com
  • subdomain2.xxxxx.com

(We just create the second one a couple of days ago)

What I'm trying to accomplish with the .htaccess:

All the subdomain2.xxxxx.com/??? urls must NOT be visible by the search engines. Infact we find out that Google started to index all the urls with both subdomains and we don't want that.

We will like to use the second subdomain just for a specific url, for example:

subdomain2.xxxxx.com/live/

All the other urls MUST not working with the second subdomain. So Google must index just this url with the second subdomain:

subdomain2.xxxxx.com/live/

Nothing else... While al the other urls (for example: subdomain1.xxxxx.com/video/ or subdomain1.xxxxx.com/photo/ and all the others) must still visible and indexed within the subdomain1. Off course subdomain1.xxxxx.com/live/ MUST NOT working because will work just with the subdomain2.

How can I do that with the .htaccess?

1

There are 1 best solutions below

0
On

Create a new file in document root called subdomain2-robots.txt: with this content:

User-agent: *
Disallow: /
Allow: /live/

Then add this rule in .htaccess right under document root:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^subdomain2\. [NC]
RewriteRule ^robots\.txt$ /subdomain2-robots.txt [L,NC]