Page 1 of 1

.htaccess direct request to file with $_get included

Posted: Tue Mar 07, 2006 2:29 pm
by blacksnday
I need to use htaccess in a cetain folder on my website.
Lets call that folder: ratings
I need all image type requests from that folder to
redirect to the file called: modify.php

modify.php will reside in the ratings folder.
modify.php will use the $_GET to determine what to do
with each image being directed to it.

How would I write a .htaccess file to direct all image
request to the modify.php as well as add the $_GET param,
i.e. modify.php?img=myimage.jpg

So that any image request will auto forward to the modify.php
and be written with the ?img= so that the modify.php knows what to do?

p.s.
I have tried to use

Code: Select all

addhandler wtmrk .jpg, gif, png
action wtmrk /ratings/modify.php
but on my current server that is not working.

I assume there are other ways to handle redirects and
need some help with other possible ways :)

Posted: Tue Mar 07, 2006 3:28 pm
by pickle
The simplest way to do this would to put this (or something syntactically correct like it) in your .htaccess file:

Code: Select all

Redirect /.*[\.gif|\.jpg|\.png]/ modify.php
The point being, you want to re-route all requests for images to modify.php. What I've written will almost certainly not work, but you hopefully get the idea. You'll notice that the requested file isn't passed on. That's fine.

In modify.php, you can get the requested filename by calling:

Code: Select all

basename($_SERVER['REQUEST_URI'])
The $_SERVER['REQUEST_URI'] isn't rewritten by the .htaccess file, so it will still have the value of the originally requested file

Posted: Tue Mar 07, 2006 4:12 pm
by blacksnday
I finally got the script to work the way I want,
but had to go about it a different way because for some
reason, trying to use .htaccess to control it has just not been working
on my current server set-up.

I just changed the <img src=> to call the image from the
modify.php file, and the modify.php uses $_GET to properly treat the image.

Then of course, I disabled hotlinking and rating folder access.


So people can still hotlink the image, if they call using the proper
img src.... (modify.php?img=)
sorta sucks though cause I dont mind normal hotlinking as long as my
watermark stuck, but have not been able to get normal htaccess methods
to work properly.