Web config 将具有哈希代码的url重定向到IIS10中具有相同哈希代码的另一个url
在IIS10(Windows Server 2019)中,我需要将一个具有可变哈希代码的url重定向到另一个具有相同哈希代码的url 例如:Web config 将具有哈希代码的url重定向到IIS10中具有相同哈希代码的另一个url,web-config,iis-10,windows-server-2019,Web Config,Iis 10,Windows Server 2019,在IIS10(Windows Server 2019)中,我需要将一个具有可变哈希代码的url重定向到另一个具有相同哈希代码的url 例如: https://www.example.com/hello/sd54effg1g5s11d5111dwds21fds2f1ffd 需要重定向到: https://subdomain.example.com/hello/sd54effg1g5s11d5111dwds21fds2f1ffd 目前,我在web.config中有一个规则: &l
https://www.example.com/hello/sd54effg1g5s11d5111dwds21fds2f1ffd
需要重定向到:
https://subdomain.example.com/hello/sd54effg1g5s11d5111dwds21fds2f1ffd
目前,我在web.config中有一个规则:
<rule name="rulename" stopProcessing="true">
<match url="^hello/[a-zA-Z0-9]+$" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(https:\/\/www\.)example.com$" />
</conditions>
<action type="Redirect" url="https://subdomain.{HTTP_HOST}/{R:1}" />
</rule>
首先,
{HTTP\u HOST}
is将与url中的https部分不匹配。因此,您应该使用^www.example.com$
而不是^(https:\/\/www\)example.com$
此外,您应该使用https://subdomain.example.com/{R:1}
而不是https://subdomain.{HTTP_HOST}/{R:1}
以满足您的需求
详细信息,您可以参考以下url重写规则:
<rule name="rulename" stopProcessing="true">
<match url="^hello/[a-zA-Z0-9]+$" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www.example.com$" />
</conditions>
<action type="Redirect" url="https://subdomain.example.com/{R:0}" />
</rule>
更新规则中的错误1。仍然不工作,但我想我已经接近了。条件部分中的模式值仍然错误。如果要匹配www.example.com
,则必须严格地匹配^www.example.com$
。你必须使用搜索引擎研究一些正则表达式。再次更新。这实际上应该更容易;-)实际上,在www上,它抛出了一个错误500。