IIS return 200 OK to any request - iis

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>

Related

How to set IIS url rewrite for http header

This is an inbound rule in my iis web site.
<rewrite>
<rules>
<rule name="ToBackEnd">
<match url="^v1/api/(.*)" />
<action type="Rewrite" url="https://172.16.8.78/v1/api/{R:1}" />
</rule>
</rules>
</rewrite>
I want to add a header (Access-Control-Allow-Origin) to the response for oly this request. There are some solutions tags in . But I do not want this? How can I set in rule?
URL rewrite outbound rule can help override the Access-Control-Allow-Origin from your application for specific URL but it can't add response header. So if you can get the expected header by rewriting your existingAccess-Control-Allow-Origin. Then outbound rule can be involved.
<outboundRules>
<rule name="outbound rule" enabled="false">
<match serverVariable="Access-Control-Allow-Origin" pattern=".*" />
<action type="Rewrite" value="*" />
</rule>
</outboundRules>
If you only need to add a header only for specific page. You can use CORS module with <location> tag
https://www.iis.net/downloads/microsoft/iis-cors-module
If you need to add another header for wildcard URL like v1/api/*. Then custom httpmodule in integrated pipeline would be a choice.

IIS Reverse proxy with multiple rules

<rewrite>
<rules>
<rule name="ReverseProxyInboundRule1" stopProcessing="true">
<match url="^a/(.*)" />
<action type="Rewrite" url="http://localhost:8086/{R:1}" />
</rule>
<rule name="ReverseProxyInboundRule2" stopProcessing="true">
<match url="^b/(.*)" />
<action type="Rewrite" url="http://localhost:8085/{R:1}" logRewrittenUrl="true" />
</rule>
</rules>
</rewrite>
At any point of time only one of the rule works another gives 404 error.
if http://localhost/a/xxx works then http://localhost/b/yyy gives 404 error.
Both rules work side by side in my environment.Did you get 404.4 error?
If so please install Application request routing and enable forward proxy in IIS manager->server node-> application request routing cache->Server proxy Settings->Enable proxy.
https://www.iis.net/downloads/microsoft/application-request-routing
If it doesn't fix the problem, please enable failed request tracing and post what you have seen.
https://learn.microsoft.com/en-us/iis/extensions/url-rewrite-module/using-failed-request-tracing-to-trace-rewrite-rules

Rewrite rule not working on IIS with using Regex

I'm trying to write a rewrite rule in on Windows Server 6.2. Although I used IIS Manager to create the code, it didn't work.
I tried stopProcess true/false, used different regex, restart server several times. Nothing changed. I followed the whole steps on Microsoft's web site on https://learn.microsoft.com/en-us/iis/extensions/url-rewrite-module/creating-rewrite-rules-for-the-url-rewrite-module
<system.webServer>
<rewrite>
<rules>
<rule name="Rewrite to e-campus" stopProcessing="true">
<match url="[^\/]+\/\/([^\/]+:?[0-9]?)\/.*" />
<action type="Rewrite" url="{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
I want to show only main URL. My domain is http://e-campus.example.com.
For example if someone go to that link: http://e-campus.example.com/Login/Student
Server should rewrite to this:
e-campus.example.com (with hiding http:// but it's not important)
So basically I just want to show main URL. But it keeps showing full path. What am I missing here?
According to your description, I found your regex match the whole url. But the iis url rewrite will not get the whole domain, it will just get the part of the url not the whole url.
For example:
If your url is http://e-campus.example.com/Login/Student., the match url part is
login/Student.
So if you want to rewrithe all the request to e-campus.example.com, you should use below url rewrite rule.
<system.webServer>
<rewrite>
<rules>
<rule name="Rewrite to e-campus" stopProcessing="true">
<match url="(.*)" />
<action type="Rewrite" url="http://e-campus.example.com/" />
</rule>
</rules>
</rewrite>
</system.webServer>

IIS Removal of Server information header

I have written the following url rewrite module to remove server version information in response header.
<rewrite>
<outboundRules>
<rule name="Remove Server header">
<match filterByTags="None" serverVariable="" pattern=".+" />
<action type="Rewrite" value="" />
</rule>
</outboundRules>
</rewrite>
This is working fine in normal flows.
However when an error page(like 500 or 404) is rendered I am able to see the IIS version information.
I need to know how to handle this rewrite for error pages as well.
Any suggestions would be appreciated
why not just create a custom error page, that way yo can make it look however you want

IIS7 rewrite rule to another domain?

I have two domains: first.com and second.com.
In these domains there are two ASP.NET applications hosted in IIS 7.
Page in application http://first.com.index references a script which source is http://second.com/script.js
Script is doing some ajax POST but browser is blocking is because cross domain restriction.
Is it possible to create rule on IIS so a specific request for http://first.com/script.js
would be passed to http://second.com/script.js (executed there and returned to client) ?
I tried to add rewrite rule in first.com but it does not work:
<system.webServer>
<rewrite>
<rules>
<rule name="test" enabled="true" stopProcessing="false">
<match url=".*/script.js" />
<action type="Rewrite" url="http://second/script.js" appendQueryString="false" logRewrittenUrl="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
Action type="Redirect" works but it is not what I am looking for cause it returns 302 response to client. I want pass request directly to second application instead.

Resources