.htaccess redirects to another file only if it exists?

I am looking for a way to redirect the request / files / image 001.jpg to / files / image001.jpg.php if the php file exists, if not just loading jpg. Any ideas?

+3
source share
1 answer

you can try it with a .htaccess file and rewrite it in mod, this should work:

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^files\/(.*)\.jpg$ $1.jpg.php

if you want to catch all extensions, change the ReweriteRule to:

RewriteRule ^files\/(.*)$ $1.php
+4
source

All Articles