Forum Moderators: phranque
are redirected to this location: http://www.mysite.com/img/viewer.php?file=7rjxt6pqdvddmf782taz.jpg
I don't want it only for that one file named 7rjxt6pqdvddmf782taz.jpg but for all files that are stored in that ( http://www.mysite.com/img/files/ )location that don't include "_thumb" in their filename.
I currently have this in my htaccess to prevent people from putting a direct link to my fullsize images, but allow them to have a direct link to my thumbnails that have "_thumb" in the filename.
This is what I current have:
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://mysite.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.mysite.com/.*$ [NC]
RewriteCond %{REQUEST_FILENAME} !.*_thumb.(gif¦GIF¦jpg¦JPG¦jpeg¦JPEG¦png¦PNG¦bmp¦BMP)$ [NC]
RewriteRule .*\.(gif¦GIF¦jpg¦JPG¦jpeg¦JPEG¦png¦PNG¦bmp¦BMP)$ - [F]
Can somebody please help me on what my new htaccess file should look like? I would appreciate any help somebody can give.
Thank you!
RewriteEngine on
#
# Prevent hotlinking (re-coded for efficiency and functional equivalence)
RewriteCond %{HTTP_REFERER} .
RewriteCond %{HTTP_REFERER} !^http://(www\.)?example\.com/ [NC]
RewriteCond %{REQUEST_URI} !_thumb\. [NC]
RewriteRule \.(gif¦jpe?g¦png¦bmp)$ - [NC,F]
#
# Redirect all full-size image requests to image-serving script
RewriteCond %{REQUEST_URI} !_thumb\. [NC]
RewriteRule ^img/files/(([^.]+)\.(gif¦jpe?g¦png¦bmp))$ /img/viewer.php?file=$1 [NC,L]
Replace all broken pipe "¦" characters above with solid pipe characters before use; Posting on this forum modifies the pipe characters.
I hope you're glad you registered... lol
Jim
I tested this and it seems to block the full sized image from being embedded onto another site. (I tested in my forum on another domain), but when a text link is posted to the full image like: http://www.mysite.com/img/files/7rjxt6pqdvddmf782taz.jpg it doesn't go to the full image which is good, but it goes to an error page:
"Forbidden
You don't have permission to access /img/files/7rjxt6pqdvddmf782taz.jpg on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request. "
Is it possible to get it so that when that text link is clicked from another site that instead of sending people to that error page, it refers them to the full sized image page that has the banners?
So when they click a link that looks like: http://www.mysite.com/img/files/7rjxt6pqdvddmf782taz.jpg
It takes them to the page: http://www.mysite.com/img/viewer.php?file=7rjxt6pqdvddmf782taz.jpg
This is the only part of the htaccess that doesn't work now.
Can you please help me get this one last feature? Thanks for the help so far, I really appreciate finally getting this stuff to work.
Is this possible?
http://www.mysite.com/img/viewer.php?file=7rjxt6pqdvddmf782taz.jpg but I would like this to work from any site. Not just urls that I own, but from anywhere on the web.
i assume "www.mysite.com" is the domain you own.
if the image url domain is referring to "someone.elses.site.com", then the browser will not be requesting that resource from your server, so there is little you can do to control how that resource is served.
you might be able to refer instead to a script at your domain that generates its own HTTP request of an offsite resource and serves it back to the user agent.
(or maybe you meant a page on "someone.elses.site.com" domain that refers to an image on "www.mysite.com"?)
That location uses the script and displays banners. The hosted image on that page, is located at http://www.mysite.com/img/files/7rjxt6pqdvddmf782taz.jpg
Is what I am hoping to have the htaccess file do, and what I've heard other people have done is this. When somebody takes the direct path of the image on my site ( http://www.mysite.com/img/files/7rjxt6pqdvddmf782taz.jpg ) and posts it as a text link on another site on the Internet, that instead of people clicking that link and being taken to the page that only see the image on a white page, instead that posted link redirects them to the script page for that same image of: http://www.mysite.com/img/viewer.php?file=7rjxt6pqdvddmf782taz.jpg
This is what I would like it to do. Simply so that anything outside of my site makes links from http://www.mysite.com/img/files/7rjxt6pqdvddmf782taz.jpg be redirected/changed so that users are taken here http://www.mysite.com/img/viewer.php?file=7rjxt6pqdvddmf782taz.jpg
Hopefully this makes it clearer on what I'm trying to get this to do.
Thanks for any additional help someone can provide.
# Redirect all full-size image requests from other sites to image-serving script
RewriteCond %{HTTP_REFERER} .
RewriteCond %{HTTP_REFERER} !^http://(www\.)?example\.com/ [NC]
RewriteCond %{REQUEST_URI} !_thumb\. [NC]
RewriteRule ^img/files/(([^.]+)\.(gif¦jpe?g¦png¦bmp))$ /img/viewer.php?file=$1 [NC,L]
The full-size images will NOT display on other sites that include (hotlink to) them. This is the best you can do, because there is no way for your server to tell the difference between an outside site using an <img src="yoursite/image.jpg"> tag on their page, and a visitor to that outside site clicking on a link. In either case, your server sees the request coming from the visitor's browser with the referrer indicating the outside site's page URL. The reason the images won't display is because with an <img src=> tag, the browser is expecting a graphic-format file in the response from your server, but now we are rewriting to a HTML page (as produced by your viewer.php script). Browsers cannot handle this switch from a graphic-format response to a text/html format, so a broken image icon will be displayed.
However, if the outside site simply presents a text link to your full-size image, then this code should operate as you describe, sending anyone who clicks on that link to the HTML page produced by your viewer.php script.
Be sure to completely flush your browser cache before testing any new code.
Jim
Forbidden
You don't have permission to access /img/files/7rjxt6pqdvddmf782taz.jpg on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
Apache/1.3.39 Server at www.mysite.com Port 80
Any ideas why it's not redirecting me to the image within the script?
Click on a text link where? -- On what site? That's a critical question, since this is referer-based rewriting.
Links on your own site won't be rewritten. Links on other sites will, as long as your browser sends a referrer header. You must flush your browser cache completely between tests.
I suspect the problem is with the definition of what you're trying to do; You can't write correct code until the specification is complete and correct...
For the 404 error, it sounds like you've declared a custom error document using the ErrorDocument directive (or perhaps your control panel) and that that custom error document does not exist at the specified path. In general, the ErrorDocument path should be specified using a path-from-root format, such as
ErrorDocument 403 /error-docs/403-error.html
To help resolve both this and other possible path-related problems, look at you server error log, correlate errors by time with the entries in your server access log, and examine the filepaths shown in the error log carefully for paths that don't correspond exactly with the actual file locations.
Jim
The htaccess code still seems to not work. I am posting the text link on my forum, which is under a different domain, and on a different server.
I am clearing my cache every single time I am testing this and clicking the link. I am clearing the cache by using FireFox's "Clear Privacy Data" link and making sure that everything is checked except, saved passwords and cookies.
From what I can tell the code isn't working and it's not how I'm testing it.
Just so I can get this working I will give you the exact data. This is what is in my htaccess:
RewriteEngine on
#
# Prevent hotlinking (re-coded for efficiency and functional equivalence)
RewriteCond %{HTTP_REFERER} .
RewriteCond %{HTTP_REFERER} !^http://(www\.)?example\.com/ [NC]
RewriteCond %{REQUEST_URI} !_thumb\. [NC]
RewriteRule \.(gif¦jpe?g¦png¦bmp)$ - [NC,F]
#
# Redirect all full-size image requests from other sites to image-serving script
RewriteCond %{HTTP_REFERER} .
RewriteCond %{HTTP_REFERER} !^http://(www\.)?example\.com/ [NC]
RewriteCond %{REQUEST_URI} !_thumb\. [NC]
RewriteRule ^img/files/(([^.]+)\.(gif¦jpe?g¦png¦bmp))$ /img/viewer.php?file=$1 [NC,L]
This htaccess file is placed in my http://www.example.com/img/ folder on my server.
The test page is this page: http://www.example.com/img/viewer.php?file=7rjxt6pqdvddmf782taz.jpg That page should show the image in the script, the way it's suppose to be displayed. Now here is the direct link to the image for that page: http://www.example.com/img/files/7rjxt6pqdvddmf782taz.jpg This page is suppose to redirect when clicked to the first page where the image is displayed within the script, but it doesn't.
That is all the specifics I can think of to give. I've uploaded the htaccess properly as a txt file and renamed it to .htaccess to make sure it is uploaded to the server in the right format as well. (I have also changed the split pipes to full pipes in my htaccess.
The only thing I can think of at this moment, is that the code in the htaccess file isn't doing the redirecting of the direct image link and rewriting it so that it instead displays the image inside the script and using the banners.
Any ideas?
[edited by: jdMorgan at 2:28 am (utc) on Feb. 25, 2008]
[edit reason] example.com [/edit]
here is a test page for you: http://www.example.com/dumpt.htm
You can clearly see that with your code you've given for an htaccess file when you click that top link it STILL takes you to the full picture.
That is not what I want. I've stated that I want it to instead rewrite the url so that it takes you to the full size image that is within the script.
You keep saying that your htaccess file works, but it is not working.
[edited by: jdMorgan at 1:54 am (utc) on Mar. 9, 2008]
[edit reason] example.com [/edit]
The rules suggested by Jim are working, so you have to find out (you can use the suggestions above as a guideline) why it is not working in your environment.