sebastian
sebastian

Reputation: 17298

htaccess rewrite condition / find pattern in file names

I want certain images in a folder to be watermarked. I got the following htaccess-chunk which is working well:

RewriteEngine On
RewriteCond %{REQUEST_URI} ^/media/image/thumbnail/(.*)([gif|jpe?g|png|bmp])$
RewriteRule ^(.*) /watermark/watermark.php?src=$1 [L]

However I only want to watermark the bigger thumbnails. There is a naming convention in our system which adds the dimensions of an image to the file name. A typical name would be:

img1_285x255.png

So how would I have to change the .htaccess in order to access files whose names end with "285x255.png" for example?

Upvotes: 1

Views: 418

Answers (1)

anubhava
anubhava

Reputation: 785146

So how would I have to change the .htaccess in order to access files whose names end with "285x255.png" for example?

You can do something like this:

RewriteRule ^(.+?285x255\.png)$ /watermark/watermark.php?src=$1 [L,NC,QSA]

Upvotes: 1

Related Questions