且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

IIS 7.5 URL重写 - 从URL重写文件夹

更新时间:2023-02-24 11:21:44

以下情况应该有效:

<rule name="MyRole" stopProcessing="true">
    <match url="LegacySite/(.*)" />
    <conditions>
        <add input="{HTTP_HOST}" pattern="^mysite.com$" />
    </conditions>
    <action type="Rewrite" url="/{R:1}" appendQueryString="true" />
</rule>

您可能希望删除检查主机名的条件。这真的很重要吗?您是否有任何其他域名绑定到您不希望重定向发生的网站?这似乎没必要。您可能只需要:

You might want to drop the conditional for checking the host name. Is that really important? Do you have any other domain names bound to that website for which you don't want the redirect to happen? It seems unnecessary. You probably only need:

<rule name="MyRole" stopProcessing="true">
    <match url="LegacySite/(.*)" />
    <action type="Rewrite" url="/{R:1}" appendQueryString="true" />
</rule>

我添加了 appendQueryString =true将任何(可选的)查询字符串参数传递给重写的URL。

I've added appendQueryString="true" to pass any (optional) query string parameters to the rewritten URL.