2016-01-24 84 views
1

目前我将所有的http请求重定向到HTTPS,但现在我想添加如果URL包含'admin'然后将HTTP请求重定向到HTTPS的条件,我如何更改规则以实现此目的例如http://www.example.com/admin/index.html)?Conditoinal HTTP重定向IIS 7

<rule name="HTTP to HTTPS redirect" stopProcessing="true"> 
     <match url="(.*)" /> 
     <conditions> 
     <add input="{HTTPS}" pattern="off" ignoreCase="true" /> 
     </conditions> 
     <action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}{REQUEST_URI}" /> 
    </rule> 

回答

0

更改URL模式:

<match url=".*admin/.*" /> 

这似乎在IIS模式匹配工具匹配您的样本数据确定。

为了匹配附加部分,例如,配置文件你可以改变正则表达式:

<match url=".*(admin|profile)/.*" /> 

如果它总是要开始adminprofile,那么你可以收紧正则表达式来^(admin|profile)/.*^意味着格局的开始,见Defining a Pattern on this screen)。

+0

其工作, 另一个问题:如何在此规则中添加任何其他术语,例如如果在URL中找到'admin'或'profile',重定向会起作用吗? – xtremist