0

I have a website for e.g.

www.domain.com

And I have another subdomain for e.g.

test.domain.com

Both my main and subdomain point to same directory which is public_html.

I want to block access to

test.domain.com/test.jpg 

but not

domain.com/test.jpg

Please note that this test.jpg is same file for both main and subdomain as they both point to same directory. So how do I block it for subdomain but not for main domain using .htaccess? Or is there any other way of doing that?

Thanks

Ali
  • 251
  • 1
  • 2
  • 9

1 Answers1

1

If test.domain.com and domain.com in one VirtualHost, easy use .htaccess and mod_rewrite:

RewriteEngine On
RewriteCond %{HTTP_HOST} =test.domain.com
RewriteRule ^test.jpg - [F]

$ curl domain.com/test.jpg
123
$ curl test.domain.com/test.jpg
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>403 Forbidden</title>
ooshro
  • 11,134
  • 1
  • 32
  • 31
  • is there a generic way to do this blocking test.* without specifying the full domain name? – Brad May 16 '22 at 12:55