1

如何在 IIS 中重写此 url

mysite.com/profile.aspx?user=foo

mysite.com/foo

我在 .htaccess 中尝试过的这种重写条件

RewriteRule /foo/(.*) /bar?arg=P1\%3d$1 [R,NE]

但是如何在 IIS Url Rewrite 中做到这一点?

4

1 回答 1

1

很简单:

<rule name="Profile Rewrite" 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="profile.aspx?user={R:1}" />
</rule>

请注意,您的 Apache 重写规则实际上根本不会达到您的预期。另请注意,您可以通过 IIS 管理器中的 URL 重写可视化配置工具轻松生成此文件。

于 2013-05-13T10:25:33.863 回答