Jump to content

block access to a folder, from within it's parent folder.


Dragen

Recommended Posts

Hi,

I have a sub-domain set up, which links to a folder in the root directory of my main domain:

main_root/sub_domain/

 

What I am trying (and failing) to do is to create a .htaccess entry in the root directory of the main domain (main_root), where the main domain website is, to stop users accessing the sub-domain via the relative path (ie; mydomain.com/sub_domain/) and instead only allowing access if they access it like so; sub_domain.mydomain.com

 

Is this possible? I would preferably send them a 404 not found, rather than 403 or anything else.

At the moment I have resorted to detecting the host, from within a .htaccess file in the sub-directory and if it is that of the main domain, then re-direct to the index page of the main domain, but I really need to be able to do this without editing the .htaccess of the sub-domain.

 

Just for reference, the code I'm using in my sub-domain is as follows:

RewriteCond %{HTTP_HOST} !^(www.)?sub_domain.maindomain.com [NC]
RewriteRule ^(.*)$ / [R,L]

 

 

Any help would be more than appreciated!

Thanks.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.