IIS URL重写-如果缺少查询参数 [英] IIS URL Rewrite - if query parameter(s) is missing

查看:68
本文介绍了IIS URL重写-如果缺少查询参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以这不是今天的日常需求:)

So this is "not your everyday requirement" for today :)

我想创建一个仅在缺少某些查询参数的情况下才重定向到其他页面的规则.

I want to create a rule that will redirect to some other page only if some query parameters are missing.

我发现了一些示例,这些示例将在参数存在的情况下进行重写/重定向,但是,如果我想检查它们是否不存在,该怎么办?

i found a few examples that will rewrite/redirect if the parameters exists, but how do i go about if i want to check if they dont exists?

例如,这将测试参数是否存在并基于该参数进行重定向:

for example, this will test if the parameters exist and redirect based on that:

        <rule name="RedirectUserFriendlyURL1" stopProcessing="true">
            <match url="^$" />
            <conditions>
                <add input="{QUERY_STRING}" pattern="^lon=([^=&amp;]+)&amp;lat=([^=&amp;]+)&amp;zoom=([^=&amp;]+)$" />
            </conditions>
            <action type="Redirect" url="/{C:1}/{C:2}/{C:3}" appendQueryString="false" />
        </rule>

我如何更改此规则以测试它们是否不存在?

how can i change this rule to test if they do NOT exist?

推荐答案

^((?! regex).)* $是正则表达式是否不包含正则表达式.在此处阅读更多信息 http://bloggernitin.blogspot.in/2007/12/regex-for-doesnt-contain.html

^((?!regex).)*$ Is the regular expression for does not contain regex. read more here http://bloggernitin.blogspot.in/2007/12/regex-for-doesnt-contain.html

如果您正在寻找不存在lon = xyz之类的东西,请使用此正则表达式^(?! lon =(xyz))这将检查字符串开头是否不存在lon参数

If you are looking for something like lon=xyz doesn't exists in params then use this regex ^(?!lon=(xyz)) this will check if lon param is not there at the start of string

更多示例-

如果只有缩放参数存在查询字符串而纬度/经度缺失的情况
例如querystring a)"lat = 23& zoom = 10" b)"zoom = 13"

正则表达式-^(?! lon =.)(?! lat =.)zoom =([[^ =&] +)
结果-a)不匹配b)匹配$ 1 = 13

现在您可以将默认值赋予其他参数.

More examples -

In case you have a case where only zoom param is there is query string and lat/lon are missing
e.g. querystring a) "lat=23&zoom=10" b) "zoom=13"

regex - ^(?!lon=.)(?!lat=.)zoom=([^=&]+)
result - a) no match b) match $1= 13

now you can give default value to other params.

这篇关于IIS URL重写-如果缺少查询参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆