How to redirect all users to http://redirect.url except "GoogleBot"
<rule name="nonbot" patternSyntax="ECMAScript" stopProcessing="true">
<match url=".*" ignoreCase="true" negate="false" />
<conditions logicalGrouping="MatchAny" trackAllCaptures="false">
<add input="{HTTP_USER_AGENT}" pattern=".+Bot.+" negate="true" />
</conditions>
<action type="Redirect" url="http://redirect.url" appendQueryString="false" redirectType="Found" />
</rule>
don't work.
As seen in the comments, the problem had to do with case.
Googlebot's name and useragent string both have the b in lowercase. The filter in the code looks for GoogleBot. Even though the OP set the filter to ignore case, it somehow didn't. So there.
Related
I am trying to redirect the two links below to the root.
My question is can you see a problem with my rule written below?
Thank You!
http://pollen.aaaai.org/nab/collectors/
http://pollen.aaaai.org/nab/collectors/index.cfm?p=Count_form
<rule name="Redirect /nab/collectors/ to http://pollen.aaaai.org/" patternSyntax="Wildcard" stopProcessing="false">
<match url="*/nab/collectors/*" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Rewrite" url="http://pollen.aaaai.org" appendQueryString="false" />
</rule>
There is a problem with your parameter, it matches the content after the hostname and does not contain "/". you can refer to below rule about redirect to root.
Note: I changed patternSyntax from wildcards to regular expressions.
<rule name="Redirect /nab/collectors/ to http://pollen.aaaai.org/" patternSyntax="Regular Expressions" stopProcessing="false">
<match url=".*" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Rewrite" url="http://pollen.aaaai.org" appendQueryString="false" />
</rule>
I can't redirect all request to one page. I used a lot of examples, but they don't work for me.
My last rule:
<rule name="redirect" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
<add input="{HTTP_HOST}" pattern="exemple" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://www.exemple.org/en/abex" redirectType="Permanent" />
</rule>
I need to redirect all pages in the site to https://www.example.org/en/abex. But I have a loop maybe because this page redirects too? or not?
I don`t know. Thanks for your answers.
You need to create negative match condition, which is excluding https://www.example.org/en/abex url from the rule:
<rule name="redirect" stopProcessing="true">
<match url="^en/abex$" negate="true" />
<action type="Redirect" url="https://www.exemple.org/en/abex" redirectType="Permanent" />
</rule>
What I would like to do is if I have link:
http://www.test.com/photo.asp?hash=hfz6rhfgz&offset=10
to rewrite as:
http://www.test.com/photo/hfz6rhfgz/?offset=10
There can be other query parameters and hash may be on some other place than the first...
The problem is it would work, but as offset is the second parameter with my rule I get:
http://www.test.com/photo/hfz6rhfgz/&offset=10
That of course causes an error as I would need ? instead of &. In the redirected URL the offset is like second parameter and in the original link it is the second.
Here is my redirect rule:
<rule name="test-redirect" stopProcessing="true">
<match url="^photo.asp$" ignoreCase="true" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{QUERY_STRING}" pattern="^(.*)hash=([\w]{8})(.*)$" />
</conditions>
<action type="Redirect" url="/photo/{C:2}/{C:1}{C:3}" redirectType="Permanent" appendQueryString="false" />
</rule>
I kind of find a solution by myself, but if there is something like
http://www.test.com/photo.asp?test=10&hash=jcekg876
It produces:
http://www.test.com/photo/jcekg876/?test=10&
so the last amp is too much, in other situations it works ok. If anybody knows how to get rid of this & it would be nice, because I need a clean URL redirect...
<rule name="test-redirect" stopProcessing="true">
<match url="^photo.asp$" ignoreCase="true" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{QUERY_STRING}" pattern="(.*)hash=([\w]{16})[&]?(.*)" />
</conditions>
<action type="Redirect" url="/photo/{C:2}/?{C:1}{C:3}" redirectType="Found" appendQueryString="false" />
</rule>
I am getting a redirect loop when I try and implement this mobile redirect I created:
<rewrite>
<rules>
<rule name="Mobile Rewrite" patternSyntax="ECMAScript" stopProcessing="true">
<match url=".*" ignoreCase="true" negate="false" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="website.com.au" />
<add input="{HTTP_USER_AGENT}" pattern="midp|mobile|phone" />
</conditions>
<action type="Redirect" url="http://mwebsite.com.au" appendQueryString="false" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
This is the catch though, the mwebsite.com.au is assigned to the same web.config as website.com.au so they are handled by the same web.config. This is the way the .net application I am dealing with is handling the request (I cannot split them up, they have to pass through this 1 web.config)
I have tested this by replacing mwebsite.com.au with google.com.au and it works perfectly but for some reason URLREWRITE cannot process the request when it has to inject mwebsite.com.au back through the same rule.
any help would be amazing.
Your rule is basically saying: if {HTTP_HOST} contains website.com.au and {HTTP_USER_AGENT} contains any of midp, mobile or phone, redirect to http://mwebsite.com.au.
As you can guess, http://mwebsite.com.au contains website.com.au.
To fix this, simply tell your condition that it should START with website.com.au using the pattern ^website.com.au.
So your rule would become:
<rewrite>
<rules>
<rule name="Mobile Rewrite" patternSyntax="ECMAScript" stopProcessing="true">
<match url=".*" ignoreCase="true" negate="false" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^website.com.au" />
<add input="{HTTP_USER_AGENT}" pattern="midp|mobile|phone" />
</conditions>
<action type="Redirect" url="http://mwebsite.com.au" appendQueryString="false" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
I'm trying to turn off HTTPS when someone hits the root of my site...
I want
https://www.domain.com/
to redirect to
http://www.domain.com/
but I also want..
https://www.domain.com/secure.aspx
or any other named page not to redirect.
Here's what I have so far but I can't get it to work. I tried a thousand ways, and read all the IIS documentation and examples on this, but I can't come up with the magic formula.
<rule name="Redirect Root Only to Non HTTP" stopProcessing="true">
<match url="\.com/$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTPS}" pattern="on" />
</conditions>
<action type="Redirect" url="http://www.domain.com" appendQueryString="false" redirectType="Found" />
</rule>
I think this is your answer:
<rule name="Redirect to HTTPS" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{URL}" pattern="^.*\.aspx$" ignoreCase="true" />
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
</rule>
<rule name="Redirect to HTTP" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{URL}" pattern="^$" />
<add input="{HTTPS}" pattern="^ON$" />
</conditions>
<action type="Redirect" url="http://{HTTP_HOST}/" redirectType="Permanent" />
</rule>
You were close .. except the actual pattern (which matches URL path part only and not domain name). The proper pattern is ^$ which means empty string which will ONLY match domain root hit e.g. https://www.domain.com/.
The full rule will be:
<rule name="Redirect Root to HTTP" stopProcessing="true">
<match url="^$"/>
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTPS}" pattern="on"/>
</conditions>
<action type="Redirect" url="http://www.domain.com/" redirectType="Permanent"/>
</rule>