Forum Moderators: phranque
First of all, sorry for my poor English.
I'm quite new to the 'rewrite_mod', but managed to write these lines, though...
What I would like to do is not directly prevent hotlinking, but showing users getting my images from any other website than mine a modified version of the image (this part is all ok, I mean the deal with php and gd!).
For this I need to pass the pic filename to my prepared php script.
My code so far:
############
1] RewriteEngine on
2] RewriteCond %{HTTP_REFERER} !^$
3] RewriteCond %{HTTP_REFERER} !^http://(www\.)?example.com(/)?.*$ [NC]
4] RewriteRule .*\.(gif¦jpg¦jpeg¦bmp)$ http://www.example.net/hl_replace_pic.php?opict=XXX [R,NC]
############
Now, on line 4] I need the complete url to the original pic (named: opict) to put where the 3 'X' are.
Hope I was clear.
I couldn't figure out how to do this :-(
Help would be very much appreciated!
Dominik
[edited by: jdMorgan at 3:45 am (utc) on Jan. 7, 2004]
[edit reason] examplified and de-linked specific URLs [/edit]
Welcome to WebmasterWorld [webmasterworld.com]!
What you are looking for is called a "back-reference" in the Apache mod_rewrite documentation [httpd.apache.org].
Adding that to your RewriteRule, and removing all unneccessary regular-expressions code gives:
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?example\.com [NC]
RewriteRule ^(.*)\.(gif¦jpe?g¦bmp)$ http://www.example.net/hl_replace_pic.php?opict=$1.$2 [R,NC]
Jim
Thanks very much for your help Jim!
(I just re-read the rewrite_mod doc...)
Now what I actuallay get with $1.$2 is the complete image filename (ie. pic.jpg). That's a good start.
For my script to find the pic I need the complete path to the pic, though.
Something like 'http://www.example.net/path/to/pic/' is missing.
%{HTTP_HOST} is not enough, 'cause I nedd the path, too.
Anybody?
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?example\.com [NC]
RewriteCond %{HTTP_HOST} ^(.*)$
RewriteRule ^(.*)\.(gif¦jpe?g¦bmp)$ http://www.example.net/hl_replace_pic.php?opict=http://%1/$1.$2 [R,NC]
Jim
[edited by: jdMorgan at 2:32 am (utc) on Jan. 8, 2004]
Thanks for all your help.
I finally reached to the following solution :
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?example\.net [NC]
RewriteRule ^(.*)\.(gif¦jpe?g¦bmp)$ http://www.example.net/hotlink_replace_pic.php?opict=%{SCRIPT_FILENAME} [R,NC]
The solution you posted Jim don't give the full path (pic not always on root).
I used the server-path-way and not an URI version, because I couldn't figure out a Rule that outputs the full URI of the pic AND because the PHP function I use ( imagecreatefromjpeg() ) accepts path in server-path-way as well.
Again thanks Jim for your time.
Hope this helps someone...
Dominik
[edited by: jdMorgan at 2:33 am (utc) on Jan. 8, 2004]
[edit reason] de-linked [/edit]