0

Windows Server 2008 R2 上的 IIS。

我有以下内容(由 URL rewrite 2.0 生成):

<rule name="RewriteUserFriendlyURL1" 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="?p={R:1}" appendQueryString="true" logRewrittenUrl="true" />

我以为这会导致

http://localhost/56321

被交互为:

http://localhost/?p=56321

任何人都可以看到它错了吗?它只是给出一个 404 错误。

我还尝试了一个 url 重定向规则,它工作正常,所以我知道该模块正在工作。

4

1 回答 1

1

您的解决方案是正确的,但与 URL 匹配的正则表达式不应以斜杠开头。以下作品:

<rule name="RewriteUserFriendlyURL1" 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="?p={R:1}" appendQueryString="true" logRewrittenUrl="true" />
</rule>

希望这可以帮助。

于 2012-05-09T10:59:24.057 回答