简体   繁体   English

IIS 7友好URL重写

[英]IIS 7 Friendly URL rewrite

I have seen a thousand examples of this: 我已经看到了一千个这样的例子:

<rule name="ex1" enabled="false" stopProcessing="true">
    <match url="^article/([^/]+)/?$" />
    <conditions>
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
    </conditions>
    <action type="Rewrite" url="article/{R:1}.html" />
</rule>

Which I can easily get to work. 我可以轻松地上班。 What I am trying to do however is to have www.mydomain.net/test rewrite to www.mydomain.net/test.html which I tried to make work with the config below. 但是,我要做的是将www.mydomain.net/test重写为www.mydomain.net/test.html,我试图使用以下配置。

<rule name="ex2" enabled="true" stopProcessing="true">
    <match url="^/([^/]+)/?$" />
    <conditions>
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
    </conditions>
    <action type="Rewrite" url="/{R:1}.html" />
</rule>

Unfortunately I haven´t had any success and I get a simple 404 on every try. 不幸的是,我没有取得任何成功,每次尝试都得到一个简单的404。 Although, when I test my regex it is successful for anything that I wish to match - eg www.mydomain.net/test. 虽然,当我测试我的正则表达式时,它对任何我想匹配的东西都是成功的-例如www.mydomain.net/test。

Can anybody provide any insight into why this is? 谁能提供任何有关这是为什么的见解?

(Using Win7, IIS7 Ultimate). (使用Win7,IIS7 Ultimate)。

You might try matching on this instead: 您可以尝试与此匹配:

"^([^/]+)/?$"

And replacing with this: 并替换为:

{R:1}.html

I'm not certain, but I don't think IIS matches on the leading / so that might be what is tripping up your rewrite. 我不确定,但是我不认为IIS在前导/上匹配,所以这可能是您的重写失败的原因。

Example: http://regexr.com?36jiq 示例: http//regexr.com?36jiq

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

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