1

SCENARIO

I am hosting a website on an Apache server, where the images are saved on an img folder.

I have already solved the issue of users accessing folders they are not intended to, placing some index.html files on such folders.

So, for instance, if a user accesses the folder website.com/img/, he will be redirected to website.com.

PROBLEM

I would like to also redirect the user when he access an image, and so, avoid making it possible to see the image and to download it.

Thus, I would like to redirect the user to website.com when he or she accesses website.com/img/image1.jpg.

Is there a way to achieve this via .htaccess? Or is there any other possibility available?

  • This question is on-topic on Webmasters site. You might find many similar ideas there yet before asking. For example, this: webmasters.stackexchange.com/q/10838 (although it is not exactly the same) – miroxlav Sep 18 '15 at 11:01
  • What exactly is the point of an image if a visitor cannot see the image. If you display the image to me in my browser, I will be able to download it, there isn't a way to stop that. – Ramhound Sep 18 '15 at 11:22
  • @miroxlav while this might also be on topic on webmasters it does not appear to be off-topic here, which would be the criteria for us migrating it without OPs input. If kouk wants it migrated then fine but currently it is good here. See this question for our stance on migrations when questions are on topic in multiple sites: meta.superuser.com/questions/2644 – Mokubai Sep 18 '15 at 11:35
  • Thanks for your help, I didn't know about the existence of the Webmasters site. Given that this question has already been answered, I will post future questions there – kouk Sep 19 '15 at 11:26
0

I guess you have the apache already configured so that the images cannot be accessed?

However, the most easy way to accomplish this is to create a .htaccess in your image folder with:

deny from all

When a user is blocked like this, he receives the HTTP-Error 403, you can add a script to this by adding to .htaccess following:

ErrorDocument 403 /restricted.php

In this script you are able to handle the redirect:

<?php    header('Location: website.com');    ?> 
0

Use an index.php file with a redirect header :

$ cat img/index.php
<?php
  header('Location: /');
?>

Or use http_redirect() function.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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