Is there any way to open another file when accessing an image via htaccess?

Viewed 28
1 Answers
RewriteRule ^(.+)\.jpg image.php [L,QSA]

This is the right idea and should "work", although it could be simplified a bit. And it is rather generic, so matches every .jpg request.

If this is not working then either:

  • You have a conflict with other directives in the .htaccess file (the order of directives can be important).

  • You have a front-end proxy that is serving your static content. This is a problem if the URL being requested maps to a physical file as the application server (ie. .htaccess) is then completely bypassed.

    If this is the case then see my answer to the following related question:
    WordPress: can't achieve direct image access redirection via .htaccess

Related