I have been trying to creat an IIS Rewrite rule that looks at the incoming Header for an API and if it contains a certain string re-direct them to a certain page and not the API (Noobs - Using documentation API Keys)
Been at it 2 hours and just can't work it out. Could anyone help?
Thanks
Finally Got it! Here is teh rule below for anyone else that is interested.
<rewrite>
<rules>
<rule name="Rewrite Noob Documentation API Key" enabled="true" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_Authorization}" pattern="^ukvd-ipwhitelist ABCD1234-1b3d-4d63-aa75-ABCDEF123456$" />
</conditions>
<action type="Redirect" url="https://xxx.co.uk/dockey.html" appendQueryString="false" />
</rule>
</rules>
</rewrite>
Related
How can convert url www.mydomain.com/home to www.mydomain.com/api/v1/home
if the requested api link don't contain api/v1
I need someone help to write iis rewrite rule in web.config to fit this case
best regards
if the requested api link don't contain api/v1
You can use the parameter ^home$ to make the requested url match only home, this way api/v1 is not contained.
<rewrite>
<rules>
<rule name="Test" stopProcessing="true">
<match url="^home$" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www.domainname.com$" />
</conditions>
<action type="Redirect" url="http://www.domainname.com/api/v1/home" appendQueryString="false" />
</rule>
</rules>
</rewrite>
Body cannot contain mydomain, so i use domainname instead of it.
I want to redirect a particular url to another server. Following is my rewrite rule:
<rewrite>
<rules>
<rule name="mydomain" patternSyntax="ECMAScript" stopProcessing="true">
<match url="(http|https)(://domain1\.)(example\.)(com|net)(/research)(.*)" />
<action type="Redirect" url="{R1}://{R3}{R4}/domain1research" />
</rule>
</rules>
</rewrite>
I am expecting that if a user types https://domain1.example.com/research, they should be redirected to https://example.com/domain1research. I've tested the expression with multiple variations on the url (.com, .net and query string) and it matches always. But when I run the website it never gets re-directed to the other page. I've URL rewrites in many web apps and they all work fine. I am not able to put my fingre on what I'm missing here.
I have tried it locally with an entry in hosts file and in a published website (Asp.Net MVC) on Azure but nothing works.
As per #lex Li's blog post and Microsoft documents, following rewrite works:
<rewrite>
<rules>
<rule name="mydomain" patternSyntax="ECMAScript" stopProcessing="true">
<match url="research" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="true">
<add input="{HTTP_HOST}" pattern="(domain1\.)(example\.(com|net)" />
</conditions>
<action type="Redirect" url="https://{C:2}/domain1research" />
</rule>
</rules>
</rewrite>
a 3rd party supplier is sending out emails to our clients with an incorrect unsubscribe link. Until they can update this URL I'm looking to correct any requests through web.config.
The correct working link should be:
https://www.example.com/my-account/alertunsubscribe?email=[email]&searchname=[searchname]
The broken link in emails is:
http://www.example.com/property/myaccount/alertunsubscribe?email=[email]&searchname=[searchname]
I've been trying to use something like the following:
<rule name="AlertUnsub" stopProcessing="true">
<match url=".*" ignoreCase="true" />
<conditions>
<add input="{HTTP_HOST}" pattern="^property/myaccount/alertsubscribe" />
</conditions>
<action type="Redirect" url="https://www.example.com/my-account/alertsubscribe" appendQueryString="true" />
</rule>
Any ideas what I'm doing wrong? I already have another rule re-directing non http traffic to https which works fine so I don't think I have to deal with that here. Same for non-www to www.
Any help would be appreciated.
Thanks
You should look for a match with the URL not {HTTP_HOST} variable, so no condition required.
Try this instead:
<rule name="AlertUnsub" stopProcessing="true">
<match url="^property/myaccount/alertunsubscribe" />
<action type="Redirect" url="my-account/alertunsubscribe" appendQueryString="true" redirectType="Found" />
</rule>
BTW there's a confusion about alertsubscribe and alertunsubscribe in the question. I assume that it is alertunsubscribe.
Well, I am not good in English actually so I couldn't explain my problem shortly in the title...
Shortly, I need to make
http://<SITE>/user/?id=<x>
to
http://<SITE>/id<x>
Is it possible in Microsoft Azure using web.config?
Inside your web.config you should insert inside <system.webServer> section this rules:
<rewrite>
<rules>
<rule name="Redirect for user" stopProcessing="true">
<match url="^user" />
<conditions>
<add input="{QUERY_STRING}" pattern="id=(\d+)" />
</conditions>
<action type="Redirect" url="/id/{C:1}" appendQueryString="false" />
</rule>
</rules>
</rewrite>
It will redirect urls like that http://<SITE>/user/?id=<x> into http://<SITE>/id<x> where <x> is digits
I've seen several blogs and questions which I believe match what I'm doing, but it's not working. URL Rewrite module is installed. I'm resetting IIS after I save this web.config file. I've tried using IIS's GUI as well with same results. Is there something else I'm not aware of?
<rewrite>
<rules>
<rule name="Redirect domain.com to www" patternSyntax="ECMAScript" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^domain.us$" />
</conditions>
<action type="Redirect" url="http://www.domain.us/{R:0}" />
</rule>
</rules>
</rewrite>
Ok, I forgot to add the binding domain.us to the site. Woops!