Jump to content

htaccess rewrite a request to both php and apache


JamesB

Recommended Posts

I'm trying to have image requests passed to php (to increment hit counts for the images) and then have apache handle the image request as normal. I'm wanting to avoid outputting the image binary data in php, to take advantage of apache's encoding/compression/caching etc.Also i'm looking to avoid external redirection with a Location header. eg.1) I visit http://127.0.0.1/image.png in the browser2) A .htaccess file catches requests with image file extensions and:2a) Gives the image filename to php2b) Outputs the image's binary data (as if there was no rewrite rule) I managed to pass image requests to php with this:

RewriteEngine OnRewriteRule ^(.*\.(png|bmp|gif|jpg|jpeg))$ on_view_image.php?path=$1

But I can't seem to let apache handle the request as normal after it's been sent to php. I've tried this: (any many other ways too)

RewriteEngine OnRewriteRule ^(.*\.(png|bmp|gif|jpg|jpeg))$ $1RewriteRule ^(.*\.(png|bmp|gif|jpg|jpeg))$ on_view_image.php?path=$1

But that appears to ignore the apache rule and only run the php rule.The only reason I've put the apache rule before the php rule there is because I read "Subsequent patterns are matched against the output of the last matching RewriteRule.".But ideally I'd want it to run the php rule first lol, in case the client connection is lost when downloading the image (assuming next rules only get ran when the previous one is complete, just guessing on that). Thanks,James

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...