homepage Welcome to WebmasterWorld Guest from 54.166.122.65
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
htaccess to prevent View Image Full Size"
Can this be done
vero

5+ Year Member



 
Msg#: 3968770 posted 1:55 pm on Aug 9, 2009 (gmt 0)

I'm using an htaccess to prevent hotlinking, which works great. The images still show up as Google thumbnails (which I dont mind) but what I don't like is the "View Image Full Size" - ie the image on its own, rather than on my website.
What I'd like is to have something where, if the address bar is just the image or ends in .jpg - ie www.example.com/images/myimage.jpg - it would redirect to the home page or another page instead.

I tried this but it didn't work. Thanks

RewriteCond %{HTTP_REFERER} !^http://([-a-z0-9]+\.)?\.jpg [NC]
RewriteRule http://www.example.com [L]

 

jdMorgan

WebmasterWorld Senior Member jdmorgan us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 3968770 posted 3:18 pm on Aug 9, 2009 (gmt 0)

You've got a requested URL-path where a referrrer should be, so that won't work. Put your own domain name where I show "example.com" here.

RewriteCond %{HTTP_REFERER} !^(http://(www\.)?example\.com/.*)?$ [NC]
RewriteRule ^images/[^.]+\.jpg$ http://www.example.com/ [R=302,L]

Best practice would really be to return a 403-Forbidden response, and then provide text links to your home page, category pages, site help, site map (HTML table of contents), and site search pages (as applicable) on your custom 403 error page. But the above snippet does what you asked for.

Jim

vero

5+ Year Member



 
Msg#: 3968770 posted 4:01 pm on Aug 9, 2009 (gmt 0)

Thanks for the reply.

Only problem is - now I don't get any of my images that I do want to appear within any of my pages.
In other words, www.example.com/images/whatever.jpg does redirect.
But none of the images in www.example.com/page1.htm show up. I tried replacing the redirect with a Forbidden response, but same thing.

This is what I have

RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://([-a-z0-9]+\.)?example\.com/.*$ [NC]
RewriteRule \.(gif¦jpe?g¦png)$ - [F]
RewriteRule ^pictures/[^.]+\.jpg$ - [F]

jdMorgan

WebmasterWorld Senior Member jdmorgan us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 3968770 posted 4:42 pm on Aug 9, 2009 (gmt 0)

You have to specify *precisely* what requested image URL-paths should redirect and which should not, and precisely under what conditions.

Be aware that RewriteConds apply only to the single RewriteRule that follows them. So your second rule in your immediately-previous post is applied unconditionally, regardless of referrer; No images below /pictures will be accessible under any conditions whatsoever -- all access to that path is forbidden.

The tough part of this is not writing the code, it is specifying which "groups" of URLs should be redirected and which should not, and under what conditions. The URL-paths must be described in terms that are testable by regular-expressions, and the conditions must be described in terms of request characteristics testable by RewriteConds looking at HTTP request and server-environment variables. There's no "magic" at work here, we have to specify everything correctly and completely.

Also, it does no good to cite "images on my pages" without telling us what the paths to those images are. So please provide multiple and thoroughly-representative example images paths which should and should not be redirected if the referrer is not your own site. We need a list.

Remember, that in the code I posted, mod_rewrite is looking only at the requested image URL and the referrer to make its decisions, and has no other way of determining "what you want." So your example list must illustrate as many characteristics of open-access and restricted-access image paths as possible. If you omit any image-path cases in the code, then those images will either be redirected when they should not be, or they won't be redirected when they should be.

Jim

vero

5+ Year Member



 
Msg#: 3968770 posted 7:04 pm on Aug 9, 2009 (gmt 0)

Sorry - I just don't know how to specify that when the call for 'example.com/pictures/pic.jpg' comes from my html code <img src=...) that it's good, but to deny access or do a redirect when the call for 'example.com/pictures/pic.jpg' comes from the browser address bar.

vero

5+ Year Member



 
Msg#: 3968770 posted 1:10 pm on Aug 10, 2009 (gmt 0)

The htaccess seems to be working now - apparently the browser was pulling images from the cache. Once I cleared the cache, all seems fine. Thanks

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved