
[英]IIS / web.config url redirect rule based on regex is not triggered
[英]Regex Redirect rule and map across domains in a web config
我需要创建一个重写 map 应该可以跨多个域访问。 IE:
https://domain1.com/Something/else --> https://domain1.com/Something-else https://domain2.com/Somethingcompletely/else --> https://domain2.com/SomethingCompletelyElse
等等
我已经尝试了很多谷歌搜索,但我真的没有找到一个解决方案,这至少对我来说是有意义的。
这是我对重写规则的尝试,这绝对不是我做过很多的事情:
<rewrite>
<rules>
<rule name="Fail bad requests">
<match url="." />
<conditions>
<add input="{HTTP_HOST}" negate="true" pattern="localhost" />
</conditions>
<action type="AbortRequest" />
</rule>
<rule name="Redirect rule for city2" enabled="true" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="{HTTP_HOST}.*" />
<add input="{testRedirects:{REQUEST_URI}}" pattern="{REQUEST_URI}" />
</conditions>
<action type="Redirect" url="{C:1}" appendQueryString="false" />
</rule>
</rules>
</rewrite>
然后是实际的rewriteMap:
<rewriteMaps>
<rewriteMap name="testRedirects">
<add key="/legal" value="/privacy" />
<add key="/good" value="/bad" />
<add key="/hi" value="/bye" />
<add key="/no" value="/not" />
<add key="/123" value="/321" />
</rewriteMap>
</rewriteMaps>
我无法测试这实际上是否有效,因为这是需要在我目前无法访问的环境中完成的事情......但我想设置一个本地 IIS 解决方案,其中两个域指向它,可能是测试它的好方法。
无论如何,如果有更简单的方法来处理跨域重写规则,我将非常感谢您对此的反馈。
谢谢各位大佬
米克尔。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.