Prevent subdomain folder access from main domain [HowTo]

If you have a few sites on your host and have subdomain for them then is very important to manage them properly as well.

Ignoring these little things may help you go but have penalty in search engine ranking and security.

It is highly recommended that you should read best practice to manage hosting.

Lets suppose you have a subdomain: sub1.domain.com

and a main domain: domain.com

and a folder for subdomain on your host at: domain.com/sub1

then you may require to prevent your subdomain from being accessed by folder on main domain. Also it is a good practice.

Solution:

RewriteEngine on RewriteBase /

#if not already blog.website.com RewriteCond %{HTTP_HOST} !^blog\.website\.com$ [NC] #if request is for blog/, go to blog.website.com RewriteRule ^blog/$ http://blog.website.com [L,NC,R=301]

Now, that the things are well managed and secured they should also be searchable.