开发者

mod_rewrite rule: How to match jpg, gif, png and bmp files

开发者 https://www.devze.com 2022-12-18 15:30 出处:网络
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 a

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号