UrlRewrite IIS to make existing image urls work wi

2019-09-17 07:15发布

问题:

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>