IIS URL重写 - 重定向的子文件夹
问题描述:
页
我想根据以下规则IIS URL重写 - 重定向的子文件夹
https://www.test.com/abc重定向在我的网站的任何流量 - >https://www.test.com/test1.aspx?c=abc
https://www.test.com/def - >https://www.test.com/test1.aspx?c=def
子文件夹必须作为查询字符串
过去,我曾经尝试这样做,它似乎并没有工作。
<rule name="Reditect1" stopProcessing="true">
<match url="^(.*)test.com/(.*)" />
<conditions>
<add input="{R:2}" pattern="^[a-zA-Z0-9_]*$" />
</conditions>
<action type="Redirect" url="/test1.aspx?c={C:0}" appendQueryString="true" />
</rule>
答
因此,经过更多的研究和试验和错误,我才弄明白了。这是我现在如何设置它。
<rule name="Redirect1" stopProcessing="true">
<match url="^(.*)$" />
<conditions>
<add input="{R:0}" pattern="^(?!\s*$).+$"/>
<add input="{R:0}" pattern="^[a-zA-Z0-9_]*$" />
</conditions>
<action type="Redirect" url="/test1.aspx?c={C:0}" appendQueryString="true" />
</rule>
注意
的规则是在网站级别设置,而不是在IIS服务器级别。因此,模式匹配忽略了域名。
^(.*)test.com/(.*) - tried matching a test.com after the actual qualified domain name. So www.test.com/test.com/abc would satisfy the condition and not www.test.com/abc
说明
的规则,进入任何一个URL匹配 - (。*)模式
第一个条件保证任何跟随合格的域名至少有一个非空格字符
第二个条件确保正在分析的部分中没有特殊字符。这是我的要求。