How to allow ONLY specific domain to access a directory?

123bear

Member
Apr 24, 2015
13
0
1
Israel
cPanel Access Level
Website Owner
hi.
I want the directory domain.com/community to be avilable ONLY trough the domain domain.community - entering domain.com/community directly will cause 404, but accessing domain.community will result 200 .

THANKS!
 
Last edited by a moderator:

123bear

Member
Apr 24, 2015
13
0
1
Israel
cPanel Access Level
Website Owner
hi. please don't shoot - i'm a newbie.
there is a directory of a domain. i want to set that directory to be viewable only through another domain.
How to do that?

Thank you!

(please correct me FIRST before blocking. thanks.)
 

123bear

Member
Apr 24, 2015
13
0
1
Israel
cPanel Access Level
Website Owner
hi.
I want the directory domain.com/community to be avilable ONLY trough the domain domain.community - entering domain.com/community directly will cause 404, but accessing domain.community will result 200 .

THANKS!
this version was previously posted by mistake - i can't edit it.
 
Last edited:

LostNerd

Well-Known Member
Mar 12, 2014
258
12
18
Hastings, East Sussex, UK
cPanel Access Level
Root Administrator
Twitter
Your best bet is to use the .htaccess file. Get it to check the host. If the host is domain.com, redirect to /index.php for example. However if the host is community.domain.com, do nothing. :)
 

123bear

Member
Apr 24, 2015
13
0
1
Israel
cPanel Access Level
Website Owner
Your best bet is to use the .htaccess file. Get it to check the host. If the host is domain.com, redirect to /index.php for example. However if the host is community.domain.com, do nothing. :)
Can you please tell me EXACTLY what write, so I can do "copy-paste"?
To my best understanding; you mean the .htaccess that in the domain.com/Directory.
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,258
463
there is a directory of a domain. i want to set that directory to be viewable only through another domain.
Hello,

Could you provide a specific example (using fake domain names) of the preferred behavior?

Thank you.
 

123bear

Member
Apr 24, 2015
13
0
1
Israel
cPanel Access Level
Website Owner
Hello,

Could you provide a specific example (using fake domain names) of the preferred behavior?

Thank you.
but i already did...
domain.com has a hosting package. 2nd domain has his own directory at the same hosting package at domain.com/example .
I want:
to block direct access to domain.com/example with 404 error
allowing access only to fakedomain.con , points to that exact same directory, with 200 o.k
 

24x7ss

Well-Known Member
Sep 30, 2014
272
19
68
India
cPanel Access Level
Root Administrator
Twitter
Hello,

You can forbid the access to specific directory by putting below in htaccess:

Options -Indexes

You can also redirect 403 error page to your custom error page by putting below in htaccess:

ErrorDocument 403 /errors/forbid.html
 

123bear

Member
Apr 24, 2015
13
0
1
Israel
cPanel Access Level
Website Owner
Hello,

You can forbid the access to specific directory by putting below in htaccess:

Options -Indexes

You can also redirect 403 error page to your custom error page by putting below in htaccess:

ErrorDocument 403 /errors/forbid.html
Will A domain be able to access it? or will it be forbidden for ALL?
 
Last edited:

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,258
463
Hello,

Have you considered simply adding the addon domain name with it's document root in the account's home directory instead of the public_html directory? Otherwise, the following third-party URL explains how to configure this:

https://my.bluehost.com/cgi/help/498

Thank you.
 

123bear

Member
Apr 24, 2015
13
0
1
Israel
cPanel Access Level
Website Owner
Hello,

Have you considered simply adding the addon domain name with it's document root in the account's home directory instead of the public_html directory? Otherwise, the following third-party URL explains how to configure this:

https://my.bluehost.com/cgi/help/498

Thank you.
thanks for your help.

To my best understanding: only "public_html" & it's subdirectories are visable to search engines - isn't moving "directory" to the root, out of "public_html"; will make my 2nd site invisible to search bots??

I don't know what i'm doing wrong: the script of bluehost doesn't work (yes i've change it accordingly).
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,258
463
To my best understanding: only "public_html" & it's subdirectories are visable to search engines - isn't moving "directory" to the root, out of "public_html"; will make my 2nd site invisible to search bots??
No, that is not accurate. The document root is configured in the Apache configuration file, so Apache knows where to look for the content associated with the domain name.

Thank you.
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,258
463
I am happy to see the issue is now resolved. Thank you for updating us with the outcome.