web.config重写规则以更新路径和查询字符串值

huangapple go评论45阅读模式
英文:

web.config rewrite rule to update the path and query string value

问题

我有一个需求,需要将URL从https:/my.original.domain.com/quickLinks/forms/formdetail?ID={XXXX}&FormTemplateID={YYYY-YYYY-YYYY-YYYY}&FormItemID={ZZZZ-ZZZZ-ZZZZ-ZZZZ} 重定向到 https:/my.original.domain.com/services/forms/formdetail?ID={AAAA}&FormTemplateID={BBBB-BBBBB-BBBBB-BBBB}&FormItemID={CCCC-CCCCC-CCCCC-CCCCC}。要注意的是,我们只需要更改粗体部分。我们需要在Web.config文件中设置重写URL以使其在.NET应用程序中生效,不需要编写任何代码。

英文:

I have a requirement to rediect the URL from https:/my.original.domain.com/quickLinks/forms/formdetail?ID={XXXX}&FormTemplateID={YYYY-YYYY-YYYY-YYYY}&FormItemID={ZZZZ-ZZZZ-ZZZZ-ZZZZ}

to

https:/my.original.domain.com/services/forms/formdetail?ID={AAAA}&FormTemplateID={BBBB-BBBBB-BBBBB-BBBB}&FormItemID={CCCC-CCCCC-CCCCC-CCCCC}

The catch here is that we only have to change the pieces which are mentioned in bold. We need the rewrite URL for this to work in web.config for the dot net application. We don't have to write any code for this.

答案1

得分: 0

使用以下规则已对我有效:

<rewrite>
    <rules>
        <rule name="查询字符串和路径更新" stopProcessing="true">
            <match url="^quickLinks/([_0-9a-z-]+)/([_0-9a-z-]+)" />
            <action type="Redirect" url="/serv-support-and-resources/{R:1}/{R:2}?id=1234&amp;FormTemplateID=%7B985861A2-58B4-4082-B95E-EF19699FC850%7D&amp;FormItemID=%7BFD8DE5D7-4078-4CD8-B4E7-A5B4EFF7F852%7D" redirectType="Permanent" appendQueryString="false"/>
        </rule>
    </rules>
</rewrite>

url="^quickLinks/([_0-9a-z-]+)/([_0-9a-z-]+)" 匹配以 quickLinks 开头的 URL,忽略大小写,然后简单地重定向到<action> 标记的 url 属性中指定的我选择的 URL 和查询字符串。

在这里,{R:1}{R:2} 相当于 quickLinks/{R:1}/{R:2}

英文:

I used the below rule that worked for me:

&lt;rewrite&gt;
		&lt;rules&gt;
            &lt;rule name=&quot;Query string and path update&quot; stopProcessing=&quot;true&quot;&gt;
                &lt;match url=&quot;^quickLinks/([_0-9a-z-]+)/([_0-9a-z-]+)&quot; /&gt;
                &lt;action type=&quot;Redirect&quot; url=&quot;/serv-support-and-resources/{R:1}/{R:2}?id=1234&amp;amp;FormTemplateID=%7B985861A2-58B4-4082-B95E-EF19699FC850%7D&amp;amp;FormItemID=%7BFD8DE5D7-4078-4CD8-B4E7-A5B4EFF7F852%7D&quot; redirectType=&quot;Permanent&quot; appendQueryString=&quot;false&quot;/&gt;
            &lt;/rule&gt;
        &lt;/rules&gt;
    &lt;/rewrite&gt;

The url=&quot;^quickLinks/([_0-9a-z-]+)/([_0-9a-z-]+) matches the url if starts with quickLinks, ignoring the case, then it simply redirects to my choice's url and query string which is mentioned in the url attribute of the &lt;action&gt; tag.

Here, {R:1} and {R:2} are as quickLinks/{R:1}/{R:2}

huangapple
  • 本文由 发表于 2023年4月19日 19:29:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/76053970.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定