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. 开发者_C百科This is for a watermark application. Currently, it only matches jpg and Jpg. How to match all four extensions?
Here is what I currently have so far.
RewriteRule ^(.*\.[jJgG].*)$ /test.php?i=$1
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.
RewriteRule ^(.+\.(jpg|gif|png|bmp)(\?.*)?)$ /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.
精彩评论