2

I have two domains for the same website. example.com and example2.com .

I don't want the /image/pic.jpg to be accessible for the example.com It means, if someone try to visit example.com/image/pic.jpg , it will show him/her error. But I want it to be accessible for example2.com visitors. So if someone visit example2.com/image/pic.jpg , they will be able to to see the picture

How can I do that using htaccess?

1 Answer 1

0

You can do this using mod_rewrite at the top of your root .htaccess file:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)example\.com [NC]
RewriteRule ^image/pic\.jpg$ - [F]

The preceding condition checks the requested host (example.com or www.example.com in this example).

This returns a 403 Forbidden if example.com/image/pic.jpg is requested. Otherwise, it doesn't do anything.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.