英文:
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&FormTemplateID=%7B985861A2-58B4-4082-B95E-EF19699FC850%7D&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:
<rewrite>
<rules>
<rule name="Query string and path update" 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>
The url="^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 <action>
tag.
Here, {R:1}
and {R:2}
are as quickLinks/{R:1}/{R:2}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论