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>
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've seen a lot of answers that come close, like this one: IIS Redirect non-www to www AND http to https but it's does not exactly match my case.
I have a website that has 2 domain aliases on top of its main domain name. Displaying the right content for each version is done in the code itself.
I am trying to use the WEB.CONFIG file to rewrite in 2 cases: when HTTPS is not used and/or when WWW is absent at the beginning of the url.
So http://example.com, https://example.com and http://www.example.com would all be rewritten as https://www.example.com Same thing if the site is visited using one of its domain aliases, for example http://examplealias.com would become https://www.examplealias.com
This answer
<rule name="Force WWW and SSL" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="^[^www]" negate="true" />
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://www.example.com/{R:0}" appendQueryString="true" redirectType="Permanent" />
</rule>
will not work for me as I cannot hard code the domain name.
I have tried this
<rule name="Force WWW and SSL" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="^[^www]" negate="true" />
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://www.{HTTP_HOST}/{R:0}" appendQueryString="true" redirectType="Permanent" />
</rule>
but this results in https://www.www.example.com if I call http://www.example.com
What would be the right way to combine both conditions?
Okay, apparently in my case, it's better NOT to combine the rules:
<rule name="Redirect naked domains (that do NOT have a custom sub-domain) to www.domain.com" enabled="true" stopProcessing="false">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern="^www." negate="true" />
</conditions>
<action type="Redirect" url="http://www.{HTTP_HOST}/{R:0}" appendQueryString="true" redirectType="Permanent" />
</rule>
<rule name="Redirect non-https urls to https" enabled="true" stopProcessing="false">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:0}" appendQueryString="true" redirectType="Permanent" />
</rule>
This works perfectly.
I have the following problem:
i want to let the users of an exact url redirect to another one.
Note: my URL immediately downloads a file.
What i want is to let the file forward to another file (it needs to download the file i'm redirecting to).
My Rule:
<rule name="File" patternSyntax="ExactMatch" stopProcessing="true">
<match url="https://SITE.be/download/DownloadFile?id=138999" />
<conditions logicalGrouping="MatchAny">
<add input="{URL}" pattern="https://SITE.be/download/DownloadFile?id=138999" />
<add input="{QUERY_STRING}" pattern="https://SITE.be/download/DownloadFile?id=138999" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" />
</conditions>
<action type="Redirect" url="https://SITE.be/download/DownloadFile?id=138111" appendQueryString="false" />
</rule>
my rule isn't working, it doesn't redirect it and when i check 'URL redirect checkers' it mentions that there isn't a redirect set on the URL.
what am i doing wrong?
Edit:
I tried:
<rule name="File" stopProcessing="true">
<match url="download/DownloadFile?id=138999" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="^site.be$" />
</conditions>
<action type="Redirect" url="https://site.be/download/DownloadFile?id=138111" appendQueryString="false" />
</rule>
with no improving (redirect checkers on google still don't trigger that theres a redirect set)
According to your iis rewirte code, I find it has problem in match url part.
This part could only match the [download/DownloadFile] not the querystring.
If we want to check the query string id, we should use url rewrite condition.
More details, you could refer to below url rewrite rule.
<rule name="File" stopProcessing="true">
<match url="download/DownloadFile" />
<conditions logicalGrouping="MatchAll">
<add input="{QUERY_STRING}" pattern="id=138999" />
<add input="{HTTP_HOST}" pattern="^site.be$" />
</conditions>
<action type="Redirect" url="https://site.be/download/DownloadFile?id=138111" appendQueryString="false" />
</rule>
Or
<rule name="File" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern="sitebe" />
<add input="{REQUEST_URI}" pattern="download/DownloadFile\?id=138999" />
</conditions>
<action type="Redirect" url="https://site.be/download/DownloadFile?id=138111" appendQueryString="false" />
</rule>
I have multiple bindings on my IIS site and I want to catch all requests to
any of the following - domainA.co.uk, www.domainA.co.uk, domainA.com, www.domainA.com
and redirect to a page on one of the other bindings on the site
www.domainB.com/my-folder/
Is this possible with URL Rewrite?
It is possible with url rewrite, you need to use this rule:
<rule name="all domains to www.domainB.com/my-folder" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="^domainA.co.uk$" ignoreCase="true" />
<add input="{HTTP_HOST}" pattern="^www.domainA.co.uk$" ignoreCase="true" />
<add input="{HTTP_HOST}" pattern="^domainA.com$" ignoreCase="true" />
<add input="{HTTP_HOST}" pattern="^www.domainA.com$" ignoreCase="true" />
</conditions>
<action type="Redirect" url="http://www.domainB.com/my-folder/{R:1}" />
</rule>
It will redirect urls:
domainA.co.uk to www.domainB.com/my-folder/
www.domainA.co.uk to www.domainB.com/my-folder/
domainA.com to www.domainB.com/my-folder/
www.domainA.com to www.domainB.com/my-folder/
www.domainA.com/something to www.domainB.com/my-folder/something (in case if you dont want that, just remove {R:1} form rule)
it is possible you could use the rewrite to redirect the domain
<rewrite>
<rules>
<rule name="Force non-WWW and SSL" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" negate="true" pattern="^www.(.*)$" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://www.{C:1}/{R:1}" appendQueryString="true" 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>