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:

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

For security purpose, I don’t want anyone to access the web app directories via these URLs:

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

RedirectMatch ^/foo/bar/app_one/(.*)$$1
RedirectMatch ^/foo/bar/app_two/(.*)$$1

With these lines added, anyone who tries to go to is redirected to

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

Related Posts:

Posts that may be related to "Prevent direct access to directories of subdomains":


A Filipino programmer and baker. 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! Running small-time online dessert shops Cookies PH and Catzie's Cakery.

Leave a Reply

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