Sign up ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I have a hosting account where I have my main site ( points to root folder), and a subfolder, where I want to have another site (

I can access by typing Also, using cPanel, I've redirected to

My question is: is there a way to prevent access by typing, so it can be accessed only by typing

EDIT: also, I don't want to to be accessed via Any help?

Hope I have explained this clearly :)

share|improve this question

migrated from Nov 2 '11 at 12:07

This question came from our site for professional and enthusiast programmers.

1 Answer 1

up vote 3 down vote accepted

If mod_rewrite is enabled on your server you may create following .htaccess file in the folder root_folder/

RewriteEngine on
RewriteCond %{HTTP_HOST} mainsite\.com$ [NC]
RewriteRule .* - [F]

This will check if the request URL ends with and deny access if it does.

EDIT: If you want to return a 404 Not Found, you may use this RewriteRule (first two lines stay the same):

RewriteRule .* - [R=404]

You can also insert other HTTP status codes instead of 404 (but replace the dash with an actual URL for redirects).

share|improve this answer
Thank you Beat. I tried, and it worked, I mean, I get a Forbiden error when accessing or However, is it possible to customize this error, for instance, change it to "Not Found" error? Thanks! – escar Nov 1 '11 at 18:21
Thanks Beat! Worked like a charm ;) – escar Nov 1 '11 at 19:36

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.