Prevent direct access to directories of subdomains

From my hosting platform (e.g. cPanel), I created two subdomains for web apps.

The web apps reside in the following directories:
/foo/bar/app_one/
/foo/bar/app_two/

And the subdomains I created are accessed through these URLs:
http://app_one.bar.domain.com (pointing to /foo/bar/app_one/ directory)
http://app_two.bar.domain.com (pointing to /foo/bar/app_two/ directory)

For security purpose, I don’t want anyone to access the web app directories via these URLs:
http://domain.com/foo/bar/app_one/
http://domain.com/foo/bar/app_two/

So, I updated the .htaccess in my public_html and added this:

With these lines added, anyone who tries to go to http://domain.com/foo/bar/app_one/ is redirected to http://app_one.bar.domain.com

Reference/Source: Prevent Access to Subdomain Folder from Main Domain

Catzie

A Filipino who is a mobile & web developer on weekdays, and a baker on weekends. When I have time to spare, I blog, play video games, watch series (usually anime), cook dishes, draw, or spend a little time with pets. When I have the rare luxury of time, I get to travel and record song covers too! Follow on Twitter: @catzie

Leave a Reply

Your email address will not be published. Required fields are marked *