Sumutiu Marius
Sumutiu Marius

Reputation: 491

mod_rewrite redirect from .png to .php

I have:

http://www.site.tk/track/aaaa.png

I want all .png files that are accessed from that folder to redirect to:

http://www.site.tk/track/track.php

So when I insert no matter what png file from that folder in another website using:

<img src="http://www.site.tk/track/bbbb.png">

The user will see the content of the "track.php"

I tryed:

Options +FollowSymLinks -MultiViews
RewriteEngine On

RewriteBase track

RewriteRule ^([A-z0-9]{6}).png /track.php

I used "RewriteBase track" because the .htaccess is on the ~/track/ folder.

This is the content of the track.php

<?php
$date = date('d-m-Y');
$time = date('H:i:s');
$ip = $_SERVER['REMOTE_ADDR'];
$ref = @$_SERVER["HTTP_REFERER"];

header('Content-type: image/png');
echo gzinflate(base64_decode('6wzwc+flkuJiYGDg9fRwCQLSjCDMwQQkJ5QH3wNSbCVBfsEMYJC3jH0ikOLxdHEMqZiTnJCQAOSxMDB+E7cIBcl7uvq5rHNKaAIA'));

$myFile = "tr.txt";
$fh = fopen($myFile, 'a');
fwrite($fh, $myFile = $time ." | ". $date . " | " .$ip. " | " .$ref. " | \r\n\r\n");
fclose($fh);
?>

All .png images will be 1px x 1px as the image that is encoded on base64 inside the tracker.php. I want to use this on emails and forums to see who saw my emails and my profile.

Upvotes: 2

Views: 942

Answers (1)

Justin Iurman
Justin Iurman

Reputation: 19016

You set a RewriteBase but not correctly.
Moreover, your rule internally rewrites to root file /track.php (which does not exist) since you put a leading slash (and so, cancels RewriteBase action).

You can replace your current code by this one (your htaccess still has to be in track folder)

Options +FollowSymLinks -MultiViews

RewriteEngine On
RewriteBase /track/

RewriteRule ^[^/]+\.png$ track.php [L]

Upvotes: 2

Related Questions