views:

49

answers:

1

I am trying to deny access to a sub-domain directory from people accessing directly rather get them to browse to the sub-domain directly. For e.g I want people to be able to go to http://test.example.com and not http://example.com/test. If they do show a 403 Forbidden error. Is this possible through htaccess ? Googled it but cant see anyone doing this. The main purpose being to disallow them from accessing the contents directly. Tried the following to no success.

<Directory /test>
  Order Deny,Allow
  Deny from all
  Allow from .example.com
</Directory>
+1  A: 

You can do a permanant redirection from example.com/test/ to test.example.com. This will make sure everyone visit your site under test.example.com. This would be more appropriate for your users.

RewriteEngine On

RewriteCond %{HTTP_HOST} ^example.com [nc]
RewriteRule ^test/(.*)$ http://test.example.com/$1 [r=301,nc] 

If you really want to show a 403 Forbidden, you can do this

RewriteEngine On

RewriteCond %{HTTP_HOST} ^example.com [nc]
RewriteRule ^test/(.*)$ / [r=403,nc] 
HoLyVieR