Denying access for Sub Domain only

Fred90

Member
Aug 24, 2017
14
3
3
Ontario, Canada
cPanel Access Level
Root Administrator
I like to block access to a subdomain to everyone except for one IP. I cannot drop an .htaccess file in this folder as the domain itself requires access.

www.domain.com has access to the following directory
/home/domain.com/public_html/photos

sub.domain.com points and to this same directory
/home/domain.com/public_html/photos

If I place the following into that directory this blocks everything for both domains accessing it.

order allow,deny
deny from all
allow from xx.xx.xx.xx

Is there another options I can use so that www.domain.com ignores it and sub.domain.com reads it.
 

rpvw

Well-Known Member
Jul 18, 2013
1,101
466
113
UK
cPanel Access Level
Root Administrator
You may be able to achieve what you want using a mod rewrite rule (perhaps using HTTP_REFERER ?)

I would suggest you test for the domain with no prefix, and also the domain with the www prefix
OR
use an IF NOT sub.domain.com ......

Hope this helps

mod_rewrite - Apache HTTP Server Version 2.4
 

Fred90

Member
Aug 24, 2017
14
3
3
Ontario, Canada
cPanel Access Level
Root Administrator
You may be able to achieve what you want using a mod rewrite rule (perhaps using HTTP_REFERER ?)

I would suggest you test for the domain with no prefix, and also the domain with the www prefix
OR
use an IF NOT sub.domain.com ......

Hope this helps

mod_rewrite - Apache HTTP Server Version 2.4
That is what I just finished adding. And tried it, all seems to be working. Just need to check the connecting server that has access.

Thanks!
 
  • Like
Reactions: cPanelMichael

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,904
2,237
463
Hello,

I'm glad to see you were able to find a suitable solution.

Thank you for updating us with the outcome.