简体   繁体   English

IIS 7 URL重写规则未触发

[英]IIS 7 URL Rewrite Rule Not Firing

I have created a rewrite rule for javascript and css versioning in IIS 7. The rule is defined as follows: 我已经在IIS 7中为javascript和css版本创建了重写规则。该规则定义如下:

<rewrite>
   <rules>
     <rule name="Js/Css Cache Rewrite" stopProcessing="true">
       <match url="(.+/public/(javascript|css)/(Debug|Release)/.+\.)\d+\.(js|css)" />
       <action type="Rewrite" url="{R:1}{R:4}" logRewrittenUrl="true" />
     </rule>
   </rules>
 </rewrite>

When I manually test the url against the regex it matches. 当我针对正则表达式手动测试网址时,它会匹配。 The url follows this pattern: http://mytestsite.com/public/javascript/Release/SomeDir/jsfile.20100915140743.js 网址遵循以下格式: http : //mytestsite.com/public/javascript/Release/SomeDir/jsfile.20100915140743.js

Any ideas on what I could be missing for the configuration? 关于配置可能缺少的任何想法?

Try this 尝试这个

 <?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="permalink">
                    <match url="article/(\D+)(\/)*$" />
                    <action type="Rewrite" url="http://mywebsite.com/article.aspx?id={R:1}" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

您的正则表达式以(.+/public/开头,翻译为“一个或多个字符,后跟/public/ /”。IIS传递给您的URL以/public/public/开头,都不是匹配您的正则表达式。您可能需要类似((^|.*/)public/

The incoming url ended up being "public/..." because of the level in IIS where it was configured. 由于IIS的配置级别,传入的URL最终变为“ public / ...”。 If I configured at a higher level then it had the full url. 如果我在较高级别上进行配置,则它具有完整的URL。 I changed my regex to the following: (.*public/(javascript|css)/(Debug|Release)/.+.)\\d+.(js|css) and it works. 我将正则表达式更改为以下内容:(。* public /(javascript | css)/(Debug | Release)/.+。)\\ d +。(js | css),它可以正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM