Welcome to WebmasterWorld Guest from 35.171.45.91

Forum Moderators: Ocean10000 & phranque

Message Too Old, No Replies

Hotlink but redirect to a dynamic file with param, got stucked

don't know how to get only the filename to reuse it

     
7:35 pm on Jan 6, 2004 (gmt 0)

New User

10+ Year Member

joined:Jan 6, 2004
posts:5
votes: 0


Hi,

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]

3:43 am on Jan 7, 2004 (gmt 0)

Senior Member

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

joined:Mar 31, 2002
posts:25430
votes: 0


Dominik,

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]

The "$1" refers back to the first parenthesized substring in the regular-expressions pattern of the RewriteRule, and the "$2" refers back to the filetype (gif, jpg, jpeg, or bmp).

Jim

2:23 pm on Jan 7, 2004 (gmt 0)

New User

10+ Year Member

joined:Jan 6, 2004
posts:5
votes: 0


Hi again

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?

5:03 pm on Jan 7, 2004 (gmt 0)

Senior Member

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

joined:Mar 31, 2002
posts:25430
votes: 0


This is as close as I can get, using a %1 back-reference to the hostname in the directly-preceding RewriteCond:

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]

This gives the complete URL-path of the file. If you need a local path, that is a different matter.

Jim

[edited by: jdMorgan at 2:32 am (utc) on Jan. 8, 2004]

8:31 pm on Jan 7, 2004 (gmt 0)

New User

10+ Year Member

joined:Jan 6, 2004
posts:5
votes: 0


Re,

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]