IIS 7友好URL重写

时间:2013-10-02 16:54:43

标签: http iis url-rewriting seo

我已经看到了一千个这样的例子:

<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>

我可以很容易地开始工作。我想要做的是将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>

不幸的是,我没有取得任何成功,每次尝试都会得到一个简单的404。虽然,当我测试我的正则表达式时,它对于我希望匹配的任何内容都是成功的 - 例如www.mydomain.net/test。

任何人都可以提供有关原因的见解吗?

(使用Win7,IIS7 Ultimate)。

1 个答案:

答案 0 :(得分:1)

您可以尝试匹配:

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

替换为:

{R:1}.html

我不确定,但我不认为IIS匹配领先/因此可能会使你的重写绊倒。

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

相关问题