开发者

IIS7 Rewrite Image Files

I'm wondering if it is possible to have an IIS7 URL rewrite rule that does something like this. When someone goes to:

http://www.mydomain.com/images/0000022_0-Hello_World.jpeg

it will request the file at: http://www.mydomain.com/images/0000022_0.jpeg

I tried to make a rule to match (.)/images/(.)-(.*).jpeg and then rewrite it to {R:1}开发者_开发知识库/images/{R:2}.jpeg, but it doesn't work. I just get a 404 error. I also tried adding the ISAPI Wildcard, but it didn't change anything.

I'm using .net 4.0

Thanks!


Assuming you use IIS Manager ( like in this article):

Try to create a rewrite rule which matches the following pattern (regular expressions):

^images/([0-9_]+)-.*\.jpeg$

As Action, choose rewrite, and fill in the following rewrite Url:

images/{R:1}.jpeg

No other rule should be executed after that (-> Stop processing of subsequent rules checkbox)


You don't need to add the ISAPI Wildcard for this as you have an extension (.jpeg) so should be handled by the StaticFile Handler.


You should put this after other rewrite rules ,for virtual folders etc..

<rule name="rule 1s" stopProcessing="true">
    <match url="\.(gif|jpe?g|png|bmp)"  ignoreCase="true" />
   <conditions>
       <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
   </conditions>
   <action type="Rewrite" url="//ressources/default.png"  />
</rule>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜