Forum Moderators: phranque
I tried this but it didn't work. Thanks
RewriteCond %{HTTP_REFERER} !^http://([-a-z0-9]+\.)?\.jpg [NC]
RewriteRule http://www.example.com [L]
RewriteCond %{HTTP_REFERER} !^(http://(www\.)?example\.com/.*)?$ [NC]
RewriteRule ^images/[^.]+\.jpg$ http://www.example.com/ [R=302,L]
Jim
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]
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