views:

22

answers:

2

I have a rule that will get the extension of every file from the url. I need to match all jpg, gif, png and bmp files. This is for a watermark application. Currently, it only matches jpg and Jpg. Can someone help me match all four extensions?

Here is what I currently have so far.

RewriteRule ^(.*\.[jJgG].*)$ /test.php?i=$1
+2  A: 

This will do it:

RewriteRule ^(.*\.(jpg|gif|bmp|png))$ /test.php?i=$1 [NC]

Note that the rule in your post is actually matching any file whose extension starts with a J or a G.

Max Shawabkeh
Thanks Max! I appreciate the help. Works great.
timmay
Your right about matching any letter starting with a j or a g. It was matching gifs as well but for some reason, wouldn't match png. I'd get a 500 server error.
timmay
+1  A: 
RewriteRule ^(.+\.(jpg|gif|png)(\?.*)?)$   /test.php?i=$1 [NC]

The [NC] enables case insensible matching. Additionally, the first .+ cares for non-empty file names. The (\?.*)? part matches optional query strings.

Boldewyn
Hi Boldewyn, thanks for your answer. I need to join so that I can vote up.
timmay