1

I have a dynamic image, which I wish to serve looking like a static image.

e.g. Current url of the image is

http://site.co.uk/media/dynamicImage.php

I wish for the image to be accessed using

http://site.co.uk/media/dynamicImage.gif

How do I use .htaccess to serve the dynamicImage.php file when dynamicImage.gif is accessed?

Please note that I don't want to rewrite ALL files in a folder as per this example: Apache - rewrite images to php file with .htaccess, I just want to rewrite the files I specify.

Community
  • 1
  • 1
Gravy
  • 12,264
  • 26
  • 124
  • 193

1 Answers1

2

Try adding these rules to the htaccess file in your document root:

RewriteEngine On
RewriteRule ^/?media/image.gif$ /media/image.php [L]

You can create as many of those RewriteRules as you need, for each specific image. This makes it so when someone requests http://site.co.uk/media/image.gif, they are actually being served the contents at /media/image.php.

If you need to keep this all within the media directory, e.g. you already have some rules in the media directory's htaccess file, you can modify the rules to look like:

RewriteRule ^image.gif$ image.php [L]
Jon Lin
  • 142,182
  • 29
  • 220
  • 220