IIS URL Rewrite - how to see rewritten URL? - iis

In IIS I've set up a basic URL Rewrite with an Inbound rule to perform a Rewrite action to another domain:
Pattern match: ^somedirectory/(.*)
Action type: Rewrite
Rewrite URL: http://www.google.com/{R:1} (using google just as a test)
The problem is, how can I actually see what the server has rewritten the URL to? When I check the IIS logs (I have "Log rewritten URL" option ticked), I would expect to see www.google.com somewhere - but it's nowhere to be found.
The pattern is definitely matching because I get the error: "502 - Web server received an invalid response while acting as a gateway or proxy server."
How can I see what is going on behind the scenes (how IIS has changed the request)?

One way is to enable "Failed Request Tracing" is IIS.
For the status code choose a range like 100-999 to capture all requests (even non-failing).
IIS will create an XML file for each request to a log directory. The XML can be viewed nicely within Internet Explorer (try the compact view tab).

Related

IIS URL Rewrite for a folder to another web server

I have an IIS webserver running a website. I've installed ARR3 to enable routing rules.
I'd like to redirect all the incoming request for the URL .mydomain/url2redirect/ to an Apache server installed on the same machine where is running SVN.
So in the inbound rule definition I've inserted the following:
Input: URL path after '/'
Pattern: *.mydomain/url2redirect/*
Action Type: Rewrite
Action URL: https://ip-address:8080/{R:2}
By testing the pattern, I get the desired result, and in the R:2 back reference I get the requested page I need to pass to SVN, but I get always a 404.
"url2redirect" doesn't exist but it should captured by the URL rewrite and forwarded to the Action URL.
I've added any outbound rule. Should I have to add something? what?
I've tried also to add a Reverse Proxy Rule, using the ARR template but, it's completely ignored, therefore I think that the routing is not working at all on IIS.
As far as I know, the url rewrite rule Pattern doesn't match the domain part.
That means mydomain will not include in the Pattern.
If you want to match the url2redirect, you should use below pattern.
url2redirect(.*)
Then I suggest you could modify your action url as below:
https://ip-address:8080{R:1}

Making an IIS redirection rule

I'm working on an IIS redirection rule where I've the following website:
https://www.test.com/smart/frid/index.html
to be redirected to the following:
https://mysmart.test.com/frid/index.html
Providing that, the parameter in the old url should be send to the new one too
For example:
https://www.test.com/smart/frid/index.html?id=260&z=3L&hsnr=3-bis
Here is the current settings:
Before you begin, understand the following process before hand and let me know if its confusing.
Application Request Routing (ARR) is an IIS extension which handles URL redirecting and rewriting features at IIS level. URL Rewrite is another extension that sets up rules using which ARR does redirection. With these steps, you can create a pattern rule on the source website. ARR will match incoming requests' URL with the URL pattern you have configured on that website. If the pattern matches, ARR can redirect the requests to destination website along with the parameters. The destination website's URL is also configured in that rule.
IIS supports these extensions which you can download. Download and install them, then they will be available when you re-open the IIS Manager program.
Once these extensions are installed, re-open IIS Manager, select the root node of websites in left side i.e. the name of your machine, then in middle section of IIS Manager, you should be able to see Application Request Routing Cache feature. Double click to open it, click on Server Proxy settings on the right, on next screen, enable the checkbox for "Enable Proxy". After that you need to add a redirection rule on the source website from which you want to transfer to destination website. For that, select the source website in IIS Manager, then in middle section of IIS where all features are listed, look for URL Rewrite, open it.
On the top Right hand side Click on Add Rule(s)… and then select Inbound Blank rule -> ok.
Note: You should create Inbound rule not outbound.
Fill the details that resembles something as follows
Name : AnyNameYouPrefer
Requested URL : Matches the Pattern
Using : Regular Expressions
Pattern : ^smart/(.*)
Ignore Case : checked
Action type: Redirect
Rewrite URL : https://mysmart.test.com/{R:1}
Append Query string : checked
Here I have written that all incoming requests' URL must have smart/ in it along with some parameters after slash "/". These requests will be transferred to destination which is specified in "Rewrite URL".
{R:1} means the URL portion that remains after that matching pattern which need to be carried from source URL to destination URL.

Using custom error pages with ARR / Application Request Routing

How can I display custom HTML instead of the following 502 response from ARR?
Traffic is directed to the server farm using a URL Rewrite rule on the server level.
Open IIS and then on the server level, in the IIS section, click "Error codes". These files are global, which is the level you will want to change for your situation. There are also site level error pages. You can modify these files or you can point them to a different file that you have customizedIIS Error Pages.

How to configure IIS ARR to do a ProxyPass?

Problem:
Need to proxy pass requests that ONLY matches the pattern: mywebsite.com/two-letter-country-code e.g mywebsite.com/es/ to mywebsite.vendor.com/es this second url is a Third-party vendor that will return content translated.
Work In progress:
IIS doesn't natively support ProxyPass so I installed "Application Request Routing (ARR)" to configure a forward proxy following the instructions in this article https://www.iis.net/learn/extensions/configuring-application-request-routing-arr/creating-a-forward-proxy-using-application-request-routing, in the step 14 while configuring the rewrite rule it says to add:
Rewrite URL: http://{C:1}/{R:0}
If my understand is correct in my case I will want to do something like
Rewrite URL: http://mywebsite.sl.vendor.com/{C:#}
Where {C:#} will return "es" or whatever the language the URL is going to.
My questions
1. Is my rewrite understanding correct?
2. Do I have to configure the Server Farms?
I noticed that by installing ARR, "Server Farm" is now available for configuration, but not sure if there is anything I need to do there.
1. Is my rewrite understanding correct?
No, since I wanted to match the two letter country codes the Patter should be:
^([a-z]{2}/(.*)|/[a-z]{2}$)
And the Rewrite URL under Action Properties should be:
https://mywebsite.sl.vendor.com/{R:0}
{R:0} will be the back-reference of specified pattern so an incoming request for mywebsite.com/es/ will be proxy passed as mywebsite.vendor.com/es were {R:0}=es/ as expected
2. Do I have to configure the Server Farms?
Is not require to do any special configuration in the server Farms to get the forward proxy working.
The third party service I was forwarding the request to, require to have the host header to be the server forwarding the request in this case mywebsite.com but in their end they were receiving mywebsite.vendor.com, to accomplish this you have to set the property preserveHostHeader to true, this can be found in the Configuration Editor

Is it possible to manipulate a request before IIS assigns that request to a specific site?

Is it possible to manipulate an inbound request at the IIS level, before it even gets assigned to site on the server?
Essentially, I want to rewrite this --
www.somegenericdomain.com?site=someotherdomain
To this --
www.someotherdomain.com
And I need to do this before IIS picks which site the request belongs to, so I need to change the host header prior to this point.
Possible, or crazy? We're running IIS7.
You can rewrite, redirect, or proxy requests.
Rewrite changes the request, but does not change the site to which it is assigned. With a rewrite you can:
return an HTTP error code (503, 404, 401, etc);
manipulate the query string or URL path. one example is to transform a query string param into a URL path element. www.server.com/default.aspx?s=foo becomes www.server.com/foo, or vice versa.
set headers in the request.
Redirect sends back a 301 or 302 response to the browser with an updated address. You can receive a request for www.example.com/foo and respond to the browser with a 302 and an updated address of www.otherdomain.com , etc.
Proxy the request. In this case the web server is said to act as a "transparent proxy". It means the initial IIS server can call out to a second server, grab the response, and then package it up back to the original requester.
These three actions are often done in combination. The tools used to perform these actions are called "URL Rewriters". IIS7 has a built-in option from Microsoft (The IIS URL Rewrite Module), and there are third-party options as well, some free and some commercial, for IIS6, IIS7, and other non-Windows web servers. Apache's mod_proxy is the big one for Linux. All of these tools do basically the same kinds of things.
To answer your specific question, NO, you cannot rewrite a request from one domain to another. For web servers, rewrite is a meaningful term, and a URL Rewrite excludes the possibility of a server change.
It is possible though, to transform a request from one server to another, either via redirect or proxy. One of those may actually be what you want, when you ask about "rewriting" a request.
I guess the whole thing is possible, but not in the way of running before IIS. One part of the server even works as a low-level driver.
But you may use URL rewriting solutions such as mod_rewrite module of Helicon Ape http://www.helicontech.com/ape/doc/mod_rewrite.htm. Having set the software globally for all the sites, you may get what you need as follows:
RewriteEngine on
RewriteCond %{HTTP_HOST} www.somegenericdomain.com [NC]
RewriteProxy (.*) http://www.someotherdomain.com$1

Resources