UrlRewrite IIS to make existing image urls work with ImageResizer

让人想犯罪 __ 提交于 2019-12-12 02:52:58

问题


We are trying to use Imageresizer with the disk cache feature as well as the sqldatareader. It expects urls to be in the form of:

http://somesite.com/image/{imageid}.{extension}

whereas all the image links in our site is currently:

http://somesite.com/image.aspx?imageid={imageid}&format={extension}

The best solution I have found so far to convert these is UrlRewrite but we are kind of doing the opposite of what it intends (taking nice urls to nasty). I have been struggling to get the rewrite rule correct for this and was hoping that somebody could help. Below is what I currently have and am aware it may be completely wrong:

 <rewrite>
     <rules>
         <rule name="RewriteUserFriendlyURL1" stopProcessing="true">
             <match url="^image.aspx?([^imageid=]+)$" ignoreCase="true" />
             <conditions>
                 <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="false" />
                 <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
             </conditions>
             <action type="Rewrite" url="image/{R:1}.jpg" />
         </rule>
     </rules>
  </rewrite>

回答1:


Was able to get the basic functionality to work with the following rule.

<rule name="Redirect Category Name and Sort By" stopProcessing="true">
    <match url="^image\.aspx$" ignoreCase="true" />
    <conditions logicalGrouping="MatchAll" trackAllCaptures="true">
        <add input="{QUERY_STRING}" pattern="^imageid=([0-9]+)" />
    </conditions>
    <action type="Rewrite" url="image/{C:1}.jpg" appendQueryString="true" />
</rule>


来源:https://stackoverflow.com/questions/18522000/urlrewrite-iis-to-make-existing-image-urls-work-with-imageresizer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!