Results 1 to 10 of 10

Thread: Using .htaccess to restrict access to images

  1. #1
    Join Date
    Jan 2006
    Location
    Derbyshire, UK
    Posts
    74
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Default Using .htaccess to restrict access to images

    I found where
    Code:
    deny from all
    in .htaccess blocks all access to that directory and prevents any images within that directory being displayed on my website. So I tried...
    Code:
    RewriteEngine on
    RewriteCond %{HTTP_REFERER} !^$
    RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomain.com/.*$ [NC]
    RewriteRule \.(gif|jpg)$ http://www.mydomain.com/angryman.gif [R,L]
    This allows my website to display any images but they can still be accessed by the public.

    Any ideas what I need to do to be able to use the images myself but not be access by anyone else?

  2. #2
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    Not sure exactly what you're trying to achieve -

    Is it just the default directory listing that you want to suppress? ( eg. When you view a directory in a web browser and it lists the files?)

    Are you wanting to prevent hot linking? (So people can't embed images from your website on their own pages)

    Please can you clarify what you need to happen/not happen and in what circumstances.
    Last edited by Beverleyh; 01-11-2013 at 07:04 PM.
    Focus on Function Web Design
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps

  3. #3
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    Quote Originally Posted by Burgin View Post
    ...Any ideas what I need to do to be able to use the images myself but not be access by anyone else?
    What do you mean by that? Since you reject the solution that allows the images to be displayed on your site, but not on other domains, I assume you're looking for more than "hotlink" protection. Do you want to deny everyone (except you, personally) access to the images?

  4. #4
    Join Date
    Jan 2006
    Location
    Derbyshire, UK
    Posts
    74
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Default

    OK... I've designed a website for a photographer and the photos are displayed as a HTML background images. All are stored in a directory called img and I want to protect them from being copied and/or hot linked. I have protected them from the RightClick > Save Background As by using an overlay div but they can be copied from their URL and via a Google Image search.

  5. #5
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    Here's how to stop direct URL access to images with htaccess : http://stackoverflow.com/questions/1...ect-url-access

    As far as blocking images from the Google images search, you can do it with a robots.txt file - here's Google's own recommendation on that : http://support.google.com/webmasters...n&answer=35308

    There will still be workarounds though - eg. Print screen - so if somebody really wanted those images, they'd probably find a way. As always, the safest way to protect anything is to not put it online.
    Focus on Function Web Design
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps

  6. The Following User Says Thank You to Beverleyh For This Useful Post:

    Burgin (01-14-2013)

  7. #6
    Join Date
    Jan 2006
    Location
    Derbyshire, UK
    Posts
    74
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Default

    @Bev... Thanks for your reply, much appreciated.

    What I'm trying to copy is what some website offering desktop posters do. Their images get listed on Bing but when you click on the VIEW FULL SIZE link a "block" message or image is displayed.

  8. #7
    Join Date
    May 2012
    Location
    Hitchhiking the Galaxy
    Posts
    1,013
    Thanks
    46
    Thanked 139 Times in 139 Posts
    Blog Entries
    1

    Default

    "Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program." - Linus Torvalds
    Anime Views Forums
    Bernie

  9. The Following User Says Thank You to bernie1227 For This Useful Post:

    Burgin (01-14-2013)

  10. #8
    Join Date
    Jan 2006
    Location
    Derbyshire, UK
    Posts
    74
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Default

    Thanks Bernie I've added the code from the above article and it's stopped hotlinking but anyone who views the source in chrome can see the image URL and click to access it. How can that be prevented?

  11. #9
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    Sadly, that's the nature of the browser and I dont think it's something you can disable via a served web page.

    A workaround could be to replace any <img src="/path/to/img.jpg" /> tags with a div tag, and then set the images as backgrounds in the CSS. Chrome will hyperlink the path to the actual CSS file when the source of the web page is viewed, allowing the user easy access to that, but once the stylesheet is open, the image paths inside aren't hyperlinked. The img paths are still visible but then a copy and paste would be needed in the address bar, which should then trigger your .htaccess protect.
    Focus on Function Web Design
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps

  12. #10
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    There's only so much you can do. This thread might interest you.

Similar Threads

  1. non www cannot access other page .htaccess
    By robert_gsfame in forum Other
    Replies: 2
    Last Post: 08-28-2010, 01:57 AM
  2. restrict dragging images to a div
    By khizar in forum JavaScript
    Replies: 2
    Last Post: 07-08-2009, 04:09 AM
  3. Restrict access to directory
    By Schmoopy in forum Other
    Replies: 7
    Last Post: 06-12-2009, 08:12 PM
  4. Restrict access to admin pages
    By vineet in forum PHP
    Replies: 4
    Last Post: 10-27-2008, 08:20 AM
  5. .htaccess directory access
    By CoolD78 in forum JavaScript
    Replies: 0
    Last Post: 03-03-2008, 06:56 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •