iis7.5使用url rewrite识别useragent的方法
作者:Doraemon 日期:2013-06-30
前段时间因为网站需要找了下通过rewrite识别用户代理的方式,因为网上关于iis7所使用的url rewrite资料比较少,这里留一篇日志,以便后查,代码如下
引用内容
<match url="^.*\.(jpg|png)$" />
这句为进行判断的文件后缀
<add input="{HTTP_USER_AGENT}" pattern="^.*(firefox|chrome).*" />
判断ua里面带有的关键词,比如firefox、chrome
<action type="Rewrite" url="xxx.htm" />
符合条件者采取的动作

<rewrite>
<rules>
<rule name="Forbidden" stopProcessing="true">
<match url="^.*\.(jpg|png)$" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_USER_AGENT}" pattern="^.*(firefox|chrome).*" />
</conditions>
<action type="Rewrite" url="xxx.htm" />
</rule>
</rules>
</rewrite>
<rules>
<rule name="Forbidden" stopProcessing="true">
<match url="^.*\.(jpg|png)$" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_USER_AGENT}" pattern="^.*(firefox|chrome).*" />
</conditions>
<action type="Rewrite" url="xxx.htm" />
</rule>
</rules>
</rewrite>
<match url="^.*\.(jpg|png)$" />
这句为进行判断的文件后缀
<add input="{HTTP_USER_AGENT}" pattern="^.*(firefox|chrome).*" />
判断ua里面带有的关键词,比如firefox、chrome
<action type="Rewrite" url="xxx.htm" />
符合条件者采取的动作
评论: 0 | 引用: 0 | 查看次数: 6151
发表评论