I am looking to dynamically serve images to web pages with htaccess based on the filename in the url. Normally, I use a nested directory structure throughout my website to serve a dynamic url based on the pseudo directory names. In this case, I would just like to query the file name (sans extension) and serve it to a PHP script so that:
/images/foo.jpg
becomes
/images/index.php?image=foo
while also let existing jpg images in this directory be served. I am sure it is easy, as I have been able to accomplish some pretty cool things with htaccess, but just not this one yet. Thanks.
like this:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^images/(.*)\.(jpg|png|jpeg|gif)$ /images/index.php?image=$1 [NC,L]
note: if you need the extension you use $2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With