Forum Moderators: phranque

Message Too Old, No Replies

hotlinking with another image file - not typical problem

         

darkage

4:53 pm on Aug 16, 2006 (gmt 0)

10+ Year Member



Ive been looking thru google and the topics here trying to solve my problem. I run a car website where people can upload images of their cars. During upload a thumbnail, a large image and a large image with "ads" is generated. The large ads image is basically a image with my url in the corners.

What id like to achieve is that when people try to hotlink to my images i serve them the ad image creating some advertisement for my website.

My image names are generated as so:
thumb: /carimages/<id>_thumb.jpg
large hotlink ad image: /carimages/<id>_link.jpg
large image: /carimages/<id>.jpg

So in short i want to serve the hotlink image when large+thumb images are requested.

This is what i have done so far:


1. RewriteEngine On
2. RewriteCond %{HTTP_HOST} =mydomain.net [NC]
3. RewriteRule ^ http://www.mydomain.net%{REQUEST_URI} [R,L]

Step 1 - 3 working - below is the new addition

4. RewriteCond %{HTTP_REFERER} .
5. RewriteCond %{HTTP_REFERER}!^http://www.mydomain.net [NC]
6. RewriteCond %{REQUEST_URI} ^/carimages [NC]
7. RewriteCond %{REQUEST_URI}!_link.jpg$ [NC]
8. RewriteRule \.jpg$ /alternate_image.$1 [L]

With my limited knowledge on mod_rewrite this is the pseudo code:
1. Turn on mod_rewrite
2. if the host is = mydomain.net (not case sensisitive comparison)
3. then redirect to www.mydomain.net

Step 1 - 3 working - below is the new addition

4. what does this mean?
5. if the referrer is not my own domain and
6. If trying to access a file under /carimages and
7. if the referrer does not end with "_link.jpg"
8. then : i dont know what this should be, but i want to do ths followin:
8a. If ends with "_thumb" remove the "_thumb" out of the imagefilename
8b. send back imagefilename + "_link.jpg"

thanks in advance for the help.

Also this site helped me out a bit with the syntax:
[widexl.com...]

jdMorgan

5:48 pm on Aug 16, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




RewriteEngine on
#
# Redirect to canonical domain if non-canonical domain is requested
RewriteCond %{HTTP_HOST} ^example\.net [NC]
RewriteRule (.*) http://www.example.net/$1 [R=301,L]
#
# If referrer is non-blank (could be blank due to HTTP/1.0 client, caching
# ISP or corporate proxy, or client "internet security" software)
RewriteCond %{HTTP_REFERER} .
# and referral is not from my site's canonical domain
RewriteCond %{HTTP_REFERER} !^http://www\.example\.net
# Remove "_thumb", add in "_link", and redirect to watermarked image
RewriteRule ^carimages/([^_]+)_thumb\.jpg$ http://www.example.net/carimages/$1_link.jpg [R=301,L]

Note several corrections to prevent exploits, duplicate content problems, and ambiguity.

For background information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].

Jim

darkage

4:00 pm on Aug 17, 2006 (gmt 0)

10+ Year Member



Jdmorgan, Thanks for your reply. I appreciate it.

Reading the links and the content you gave me i came up with this (see below) which works, but id like you to have a look at to ensure that there is no risk of exploitation, hacking, etc.

Thanks in advance.

PS A typical image image URL looks like this:
/carimages/2006/31/104_1154642654.jpg
</carimages/YYYY/weekno/carid_timestamp.jpg>

------------------
<VirtualHost *:80>
ServerName mydomain.net
ServerAlias www.mydomain.net
DocumentRoot "/blabla"
RewriteEngine On

# rewrite mydomain.net to www.mydomain.net begin
RewriteCond %{HTTP_HOST} ^mydomain\.net [NC]
RewriteRule (.*) [mydomain.net$1...] [R=301,L]
# rewrite mydomain.net to www.mydomain.net end

# rewrite thumb carimages to ad images begin
# If referrer is blank (could be blank due to HTTP/1.0 client,
caching ISP or corporate proxy, or client "internet security"
software) or URL directly entered into browser then dont show ad
image
RewriteCond %{HTTP_REFERER} .

# and referral is not from my site's canonical domain
RewriteCond %{HTTP_REFERER}!^http://www\.mydomain\.net

# if asking for thumb image in /carimages then return large ad
image
RewriteRule ^/*carimages/*([0-9]{4}/*[0-9]{2}/*[0-9]*_[0-9]*)
_thumb\.jpg$ [mydomain.net...]
[R=301,L]
# rewrite thumb + large carimages to ad images end

# rewrite large carimages to ad images begin
# If referrer is blank (could be blank due to HTTP/1.0 client,
caching ISP or corporate proxy, or client "internet security"
software) or URL directly entered into browser then dont show ad
image
RewriteCond %{HTTP_REFERER} .

# and referral is not from my site's canonical domain
RewriteCond %{HTTP_REFERER}!^http://www\.mydomain\.net

# if asking for large image in /carimages then return large ad
image
RewriteRule ^/*carimages/*([0-9]{4}/*[0-9]{2}/*[0-9]*_[0-9]*)
\.jpg$ [mydomain.net...] [R=301,L]
# rewrite large carimages to ad images end
</VirtualHost>