Reputation: 17124
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=([^=&]+)&lat=([^=&]+)&zoom=([^=&]+)$" />
</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?
Upvotes: 2
Views: 2717
Reputation: 36
^((?!regex).)*$ Is the regular expression for does not contain regex. read more here http://bloggernitin.blogspot.in/2007/12/regex-for-doesnt-contain.html
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
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.
Upvotes: 1