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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.