Forum Moderators: phranque

Message Too Old, No Replies

folder redirection

Re direct all folder access's to a script

         

baiwan

1:09 pm on Apr 28, 2012 (gmt 0)

10+ Year Member



I'm embarrassed to ask, but I just cant seem to get this right :(

I want all file requests for a particular folder to be processed by my script, in another folder.

In this case, re-sizable images are fetched from a particular folder, and the script provides a re-sized version.

So,

http://mysite.com/size/picture.jpg would run my script at http://mysite.com/scripts/picturesizer.php 


I expect it would look something like this:

RewriteRule ^size.*$ /scripts/picturesizer.php [L]



This isn't quite right though, is it? What should it be?

lucy24

7:32 pm on Apr 28, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You're almost there. But you need to capture the name of the file-- beginning with "size/" if that's where they all live-- and then feed that captured name to your script. The name of the file to be rewritten or redirected has to be included in the target, most likely as a query string.

g1smd

9:27 pm on Apr 28, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Something like this:

RewriteRule ^size/([^.]+)\.jpg$ /scripts/picturesizer.php?name=$1 [L]


Your PHP script MUST return a 404 response when there is no image for this request.

baiwan

1:36 pm on May 1, 2012 (gmt 0)

10+ Year Member



Thanks for your responses - I've got it doing excactly what I want now :)