Find out how you could stop people browse your site through the subdomain of your main primary domain.

You could prevent subdomain access by writing some script in the .htcaccess file of the sub-domain folder.

We have one hosting account, however there are several websites that is hosted on the same one web hosting account.

When we created a sub-domain name for the additional website people can browse through the actual website URL or through the sub domain URL.

For example we have ijsol as a subdomain of itjungles.com.

If you don't setup the blocking script the people can browse to the www.ijsol.com with the following URL:

  • www.ijsol.com
  • ijsol.itjungles.com
  • www.itjungles.com/ijsol

By having multiple URL Google search engine could define your site have multiple duplicated content. To stop this use the following script:

To stop this URL www.itjungles.com/ijsol from being seen:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?itjungles.com$ [NC]
RewriteCond %{REQUEST_URI} ^/ijsol/(.*)$
RewriteRule ^(.*)$ - [L,R=404]

To stop this URL ijsol.itjungles.com from being seen:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^ijsol.itjungles.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.ijsol.itjungles.com$ [OR]
RewriteCond %{HTTP_HOST} ^ijsol.com$
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^(.*)$ http://www.ijsol.com/ [R=301,L]

To stop both of the URLs:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?itjungles.com$ [NC]
RewriteCond %{REQUEST_URI} ^/ijsol/(.*)$
RewriteRule ^(.*)$ - [L,R=404]

RewriteCond %{HTTP_HOST} ^ijsol.itjungles.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.ijsol.itjungles.com$ [OR]
RewriteCond %{HTTP_HOST} ^ijsol.com$
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^(.*)$ http://www.ijsol.com/ [R=301,L]

 

Note: you must place this script in the .htaccess file in the sub domain folder. In this instance you would place it in the ijsol website folder.

 
SEO Building Block