[英]write a redirect rule in web.config in asp.net application
I have a help section on a web site, which for now I want it to redirect to another place. 我在网站上有一个帮助部分,现在我希望它重定向到另一个地方。 The rest of the site should stay the same, which means that only the help section/content should make the user go to another site:
该网站的其余部分应保持不变,这意味着只有帮助部分/内容应使用户转到另一个网站:
device.domain.net/collection/hgkhghj should return to device.domain.net/collection device.domain.net/collection/hgkhghj应该返回到device.domain.net/collection
I can have anything at the place of hgkhghj . 我可以在hgkhghj那里代替任何东西。 If i am writing device.domain.net/collection then it should return device.domain.net/collection
如果我正在写device.domain.net/collection,那么它应该返回device.domain.net/collection
<rule name="Help Redirect" stopProcessing="true">
<match url="(.*)/collection(.*)" ignoreCase="true" />
<action type="Redirect" url="http:/device.domain.net" appendQueryString="false" redirectType="Permanent" />
</rule>
but currently it is returning to device.domain.net. 但目前它返回到device.domain.net。
I want to make one more Rule in which if i enter device.domain.net/gcfhgg then it should return to device.domain.net. 我想再制定一条规则,如果我输入device.domain.net/gcfhgg,则它应该返回到device.domain.net。
<rule name="Help Redirect" stopProcessing="true">
<match url="(.*)" ignoreCase="true" />
<action type="Redirect" url="http://device.domain.net" appendQueryString="false" redirectType="Permanent" />
</rule>
But it is not working. 但这是行不通的。
For your first rule you could use the following (assuming it is on the same domain): 对于第一个规则,您可以使用以下命令(假设它在同一域中):
<rule name="Help Redirect" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^collection/(.*)" />
<action type="Redirect" url="collection" appendQueryString="false" redirectType="Permanent" />
</rule>
If this is on another domain you will need ARR installed as well. 如果在另一个域上,则还需要安装ARR。 Your second rule is more complicated as it looks as if you are attempting to perform a redirect only if you hit a 404 page.
您的第二条规则更加复杂,因为看起来好像您仅在命中404页时才尝试执行重定向。 This is something I have never done using rewrite rules.
这是我从未使用重写规则完成过的事情。 Is there a reason for doing this as opposed to showing a custom 404 page?
与显示自定义404页面相反,这样做是有原因的吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.