![](/img/trans.png)
[英]Response.Redirect on Page with Url Rewritten by IIS Url Rewrite Module
[英]IIS URL Rewrite - Redirect for subfolder to page
我想根據以下規則重定向網站上的所有流量
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匹配-模式(。*)
第一個條件確保合格域名之后的所有內容至少具有一個非空格字符
第二個條件確保正在解析的部分中沒有特殊字符。 這是我的要求。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.