How to configure IIS to return 200 OK to any URL request?
Any request that arrives to IIS should immediately return 200 with an empty body.
It is not important how this is achieved, either thru configuration or code.
As lex says, we could use url rewrite to achieve your requirement. You could install url rewrite firstly by using this url:https://www.iis.net/downloads/microsoft/url-rewrite.
Then you could add below rule into the web.config.
<rewrite>
<rules>
<rule name="Customresponse" stopProcessing="true">
<match url=".*" />
<action type="CustomResponse" statusCode="200" statusReason="test" statusDescription="test" />
</rule>
</rules>
</rewrite>
We have recently started using MVC which has modified the way we browser to our site in IIS.
We currently have a website address like this:
http://myserver.mydomain:123/
What we need is to redirect to this site:
http://myserver.mydomain:123/web
This needs to work for all pages in our site (i.e /web/login.aspx /web/workflow.aspx etc.)
This is what I have currently setup our configuration in our web.config file:
<rewrite>
<rules>
<rule name="Root Hit Redirect" stopProcessing="true">
<match url=".*123" />
<action type="Redirect" url="/web" />
</rule>
</rules>
</rewrite>
This does not work for all occurrences.. Please help
I even tried this and still no luck..
<system.webServer>
<rewrite>
<rules>
<rule name="test">
<match url="^https://localhost:3443/$" />
<action type="Redirect" url="web/login.aspx?ReturnUrl=%2fweb" redirectType="Found" />
</rule>
</rules>
</rewrite>
</system.webServer>
I have an IIS 10 with ARR 3.0 and websockets
If I'm using directly iis, my websockets works great.
The websocket's address is like ws://IP_SERVER:PORT/ws/XXXX
If I'm using the same iis (and same site with a rewrite url rule) as reverse proxy, my websocket connects and disconnects forever.
The websocket's address is like ws://DOMAIN:PORT/ws/XXXX
The Url Rewrite configuration is:
<rewrite>
<rules>
<rule name="ReverseProxyInboundRule1" stopProcessing="true">
<match url="(.*)" />
<action type="Rewrite" url="{C:1}://localhost:1880/{R:1}" />
<conditions>
<add input="{CACHE_URL}" pattern="^(.+)://" />
</conditions>
</rule>
</rules>
</rewrite>
Can you help me please ?
Thanks
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>
I've noticed that with .NET MVC sites, you're able to hit URLs with multiple forward slashes, for example:
http://www.example.com//category
http://www.example.com//category//product
The URL loads fine and everything works, however, I've been asked to stop this from happening.
I've been trying to use IIS URL Rewrites to get it working:
<rewrite>
<rules>
<rule name="Remove multiple slashes" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{UNENCODED_URL}" matchType="Pattern" pattern="^(.*)//(.*)$" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="{C:1}/{C:2}" />
</rule>
</rules>
</rewrite>
However, the results seem very temperamental. Sometimes the product URL will redirect, sometimes it won't and the same thing happens with the category. It's almost like the URL is being cached by the application.
Does anyone know if I can disable any caching that's in place, or if there is another way to get around this multiple slash issue?
Any help is much appreciated.
In the end, I have resorted to using a code behind redirect to get it working.
The issues I was having using the IIS URL Rewrites was due to the way IIS caches the redirects. When I disabled caching completely, as WouterH suggested, it worked. However, I'm not comfortable disabling caching in this way as it could introduce performance issues.
My fix was to use a code behind redirect in the Global.asax.cs file:
protected void Application_BeginRequest(object sender, EventArgs e)
{
string requestUrl = Request.ServerVariables["REQUEST_URI"];
string rewriteUrl = Request.ServerVariables["UNENCODED_URL"];
if (rewriteUrl.Contains("//") && !requestUrl.Contains("//"))
Response.RedirectPermanent(requestUrl);
}
I would have liked to use IIS URL Rewrite to get this working, unfortunately I didn't have the time to continue down that line.
Interestingly, the below method did work, however, the HTTP_X_REWRITE_URL is added by the Helicon ISAPI Rewrite which I'm running locally, but is not available on our production server.
<rewrite>
<rules>
<rule name="Remove multiple slashes" stopProcessing="true">
<match url=".*" />
<action type="Redirect" url="{REQUEST_URI}" />
<conditions>
<add input="{HTTP_X_REWRITE_URL}" pattern="([^/]*)/{2,}([^/]*)" />
</conditions>
</rule>
</rules>
</rewrite>
URL Rewrite Module
As IIS automatically normalizes url's with double slashes, you can try to redirect to the normalized url like this:
<rewrite>
<rules>
<rule name="Remove multiple slashes" stopProcessing="true">
<match url=".*" />
<action type="Redirect" url="{REQUEST_URI}" />
<conditions>
<add input="{UNENCODED_URL}" pattern="(.*?)[/]{2,}$" />
</conditions>
</rule>
</rules>
</rewrite>
You can also try to disable caching of the URL rewrite module:
Disabling internal caching of rewrite rules
To disable caching of inbound rewrite rules in URL Rewrite Module run
the following command from an elevated command prompt:
reg add HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\InetStp\Rewrite /v
RewriteCacheEnabled /t REG_DWORD /d 0
I have a small feeling that you'll have to restart the webserver after this change :)
Other option #1: non-cacheable server variable
This idea just popped into my mind:
use a non-cacheable server variable in the rule, f.e. try with HTTP_USER_AGENT
<rewrite>
<rules>
<rule name="Remove multiple slashes" stopProcessing="true">
<match url=".*" />
<action type="Redirect" url="{REQUEST_URI}" />
<conditions>
<add input="{UNENCODED_URL}" pattern="(.*?)[/]{2,}$" />
<add input="{HTTP_USER_AGENT}" pattern=".*" />
</conditions>
</rule>
</rules>
</rewrite>
You can explore other server variables here
Other option #2: clear browser cache
During web development, make sure you use Ctrl+F5 to refresh your page, or clear your browser cache after making changes like updating rewrite rules etc. Otherwise you can spend hours of watching to the same problem while it was just your browser that needed to refresh its cache.
Other option #3: IIRF
If you really can't get it to work with the IIS URL Rewrite Module, you can give the open-source ISAPI module IIRF a try. It accepts rules similar to mod_rewrite for Apache.
Try following
<rule name="RemoveMultipleSlashes" patternSyntax="ECMAScript" stopProcessing="true">
<match url=".*" />
<action type="Redirect" url="{REQUEST_URI}" />
<conditions>
<add input="{UNENCODED_URL}" pattern="([^/]*)/{2,}([^/]*)" />
</conditions>
</rule>