I have two applications. One of which is going to handle authentication across a range of products. Because of this, from each one I want to rewrite a URL from each individual website to our "authentication" project. It would look something like this.
http://www.mywebsite.com/api/profile/login -> http://www.myauthentication.com/api/profile/login.
So essentially pushing the request cross domain.
For this I have setup ARR and URL Rewriting in IIS. However I can't seem to get it to work, and I have a feeling URL Rewriting is not running on requests that would normally cause a 404. I think this because on a REDIRECT request (301 redirect), the config works perfectly. When I use a rewrite, I get a generic 404 page.
The rules configuration looks as per below :
<rules>
<rule name="Route the requests for the Profile API." enabled="true" stopProcessing="true">
<match url="^profiles/(.*)" />
<action type="Rewrite" url="http://authentication.local/api/profiles/{R:1}" logRewrittenUrl="true" />
</rule>
</rules>
It should be noted that I am using the WebAPI, not MVC, which I'm not sure if that is causing issues or not. Because the redirect works but not the rewrite, I'm sure I've got everything installed OK in IIS.
For ARR, I have simply ticked "Enable Proxy" but I am unsure if I need to do anything else.
I managed to solve this by adding an ignore route for ARR.
RouteTable.Routes.IgnoreRoute("api/profiles/{*pathInfo}");
Related
I have a strange business case where I need any time a URL is called on my web server that it is re written with the incoming URL.
Example:
Incoming URL
/site/1
URL that it is going to
/innerlink/2
In the browsers URL
/innerline/2 would show /site/1
If you can answer this question or get me to some material that could help me in doing this it would be greatly appreciated. Thanks!
The name of this approach "URL rewriting". In IIS you can achieve it with URL rewrite module.
In your case when you just need to rewrite /site/1 to /innerlink/2 you need to do the following:
Install URL rewrite module for IIS (it might be already installed)
In your web.config you need to add this rewrite rule:
.
<rule name="Laravel5" enabled="true" stopProcessing="true">
<match url="^site/1$" />
<action type="Rewrite" url="/innerlink/2" />
</rule>
And now if you will open in your browser this link {YOUR DOMAIN, IP OR HOSTNAME}/site/1 it will make request to /innerlink/2 (but browser will keep showing /site/1)
P.S. Also you can find some useful rewrite/redirect rules in this article: https://host4asp.net/top-iis-rewrite-rules/
I've been trying to use the URL Rewrite module to create a rule that looks for any set of two or more forward-slashes in the URL (past the first set) that will redirect the browser to a URL with all sets of multiple forward slashes replaced with just one. Example:
http://myhost.com/abc//def//ghi//jkl//iisstart.png
should redirect to
http://myhost.com/abc/def/ghi/jkl/iisstart.png
I already understand that IIS sees these two URLs as functionally equivalent, but for this public-facing site we want to avoid any chance that crawlers will index URLs with the multiple forward slashes; hence the redirection. So here's the rule I put together:
<rule name="Redirect URLs with Multiple Forward Slashes" enabled="true" patternSyntax="ECMAScript" stopProcessing="true">
<match url=".*" />
<action type="Redirect" url="{URL}" appendQueryString="true" />
<conditions logicalGrouping="MatchAny">
<add input="{UNENCODED_URL}" pattern="//" />
</conditions>
</rule>
I tested this on my local box, and it produced the expected outcome (the redirection). I copied it into a web.config on a development server and tried it out, but it didn't work. I even took the path of making sure the URL Rewrite installation matched the version on the development server (it's 2.0, and upgrading would be a pain in our large production server farm so I'd like to avoid that). After that, I took into account that our development server, by design, only serves up HTTPS, while I'd been testing in HTTP on my local box. When I enabled HTTPS on my local box, the rewrite rule didn't work with an HTTPS URL but worked fine with an HTTP URL pointing to the same resource.
All the URL Rewrite documentation I've looked at makes reference to HTTP, and there are no references to HTTPS. What am I doing wrong here?
For the record - my local box is running Windows 10, and has IIS version 10. The dev server is running Server 2012, and has IIS version 7.5.
I'm struggling with IIS' URL Rewrite and ARR Modules.
Basically, here's the current state of affairs:
I have a main webserver, awnsering all of my requests. Let's name this MAINWEBSERVER.
I have a secondary server with a specific application that's working as intended if you access it internally but needs to be exposed to the outside via domain to work as a webservice. Let's name this server APPSERVER.
I wish to receive my requests on MAINWEBSERVER and rewrite the URL if it matches my wildcard.
In this case, my Wildcard is https://example.com/MYAPPLICATION* .
And my desired redirect is https://APPSERVER/MYAPPLICATION/WhateverIsLeftInTheUrl .
So here's my rule sitting on my MAINWEBSERVER:
<rewrite>
<rules>
<rule name="Rewrite to Application" patternSyntax="Wildcard" stopProcessing="true">
<match url="https://example.com/MYAPPLICATION*" />
<action type="Rewrite" url="https://APPSERVER/MYAPPLICATION{R:1}" logRewrittenUrl="true" />
</rule>
</rules>
</rewrite>
NOTE: I need the URL rewritten for certificate SAN purposes (it won't validate APPSERVER/MYAPPLICATION, so I want to use a mask that is validated by my certificate, such as https://example.com/MYAPPLICATION).
The steps I took were:
Installing ARR (activating proxy settings);
Installing URL ReWrite Module;
Configuring wildcard rule for https://example.com/MYAPPLICATION;
Configuring rewrite for https://APPSERVER/MYAPPLICATION{R:1} (in case it has querystrings I wish to keep them);
Generated personal certificates to validate HTTPS requests between MAINWEBSERVER and APPSERVER;
Whenever I make my request the rule is ignored (despite the same URL matching the wildcard perfectly) and the default website application awnsers, considering my wildcard a querystring parameter.
I've tried this both at server level and at default website level, even with Reverse Proxy Rules. I also have experimented with Fiddler and Failed Request Tracing but to no effect.
In the FRT all that is displayed is a 302 HTTP CODE and in the end a 200 Status Code when the default website loads.
Note that I believe this was working on a different server before, using this same rule although there was no default website.
I have React app which ends up being built with webpack. We host an API which this app talks to on Azure and would like to host the UI built on top of it out there as well.
When hitting the URL the first time, and navigating around, all of the history location stuff works. However, when we refresh the page, we receive a 404 error (which is to be expected if IIS is serving this).
Is it possible to configure Azure to handle this sort of thing? Should we just give up on this type of application and host a webpack vm?
Similar questions:
Reactjs HistoryLocation get 404 on refresh
React-router urls don't work when refreshing or writting manually
If do understand your question and situation correctly, the solution would be to redirect all requests to your only one HTML page (assuming index.html).
This can be achieved with the URL rewrite module of IIS.
By default any Azure Web App will have a file in its web root folder named web.config. This is standard XML file. Open it with favorite editor and locate <system.webserver> section. Then place the following additional sections inside. Note, the <rewrite> element should be direct descendant of the <system.webserver> one:
<rewrite>
<rules>
<rule name="Rewrite to index.html">
<match url=".*" />
<action type="Rewrite" url="index.html" />
</rule>
</rules>
</rewrite>
Again, based on the assumption that you serve everything from index.html, you can change this file in the rewrite rule to represent the file you are serving content from.
Thanks in advance for your help.
In my environment, I configured IIS to act as a reverse proxy and forward requests to certain paths to an application server on another host. In order to do this, I used Application Request Routing (ARR) and URL Rewrite modules, I create my rule and everything's working fine.
IIS is responsible to authenticate clients using NTLM, so my question is: is it possible to pass the authentication credentials (at least the username) to my application server after authenticating the user?
I tried to do this adding a custom header to my requests, writing a rule like this:
<rule name="ForwardToApplicationServer">
<match url=".*" />
<serverVariables>
<set name="HTTP_AUTH_USER" value="{AUTH_USER}" />
</serverVariables>
<action type="Rewrite" url="http://myappserver/myapp/{R:0}" logRewrittenUrl="true" />
</rule>
But it doesn't work: when I read it on my application my header is alwasy empty. I also tried with and but none of these worked.
So, what am I doing wrong? Should I use another server variable? Am I missing something?
More in general: is it possible to do what i'd like to do?
Again, thanks in advance for your help, and please forgive me if I'm asking something obvious but I'm new to using IIS and I couldn't find anything that helped me.
http://weblogs.asp.net/owscott/an-intro-to-iis-url-rewrite-plus-redirecting-urls-to-www-web-pro-week-8-of-52
{REMOTE_USER}, {LOGON_USER} & {AUTH_USER} do not work with URL-REWRITE, ...
You can use www.isapirewrite.com which runs later in the stack and has a handle on the auth data.