Jump to content
JamesB

htaccess rewrite a request to both php and apache

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

Share this post


Link to post
Share on other sites

<IfModule mod_rewrite.c> RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*\.(png|bmp|gif|jpg|jpeg))$ on_view_image.php?path=$1 </IfModule>

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...