Using IIS ARR to rewrite external URL - iis

This might be a stupid question, however we have a website which we'll call http://example.com and we're using YuDu to publish some of our brochures online.
The URL's YuDu have given us are in the format http://content.yudu.com/htmlReader/SomeString/SomeName/SomeFile.html however we want to use our own URL's for these files:
i.e. http://example.com/ebrochure/SomeBrochure
I can setup URL rewriting for this, but it obviously redirects to the YuDu domain. Looking online it appears that I 'may' be able to use the IIS Application Request Routing module for this...but I'm at a loss as to how to do this. Everything I've found so far uses localhost and/or domains you already own for this.
So my question is:
Is my request even possible?
If so...could anyone point me in the right direction to do it?
Thanks in advance.
Matt

I don't think it's possible to do that. As far as the content must be served by yudu.com, you can only use redirections (with URL rewriting or by configuring a redirect in Application Request Routing). It will anyway end with a redirect. You could only manage this if yudu.com was one of your domains, which doesn't seem to be.
The only way I see if you really want to serve this content behind your example.com URL is using an iframe. But I don't know if Yudu will allow this.
Good luck !

It is definitely possible.
1) You need to install ARR module
2) In IIS manager you should enable reverse proxy
2.1) On server node click "Application Request Routing Cache"
2.2) Click "Server proxy settings" and click "Enable proxy", then "Apply"
3) In web.config add this rule:
<rule name="rewrite /ebrochure/SomeBrochure" stopProcessing="true">
<match url="^ebrochure/SomeBrochure$" />
<action type="Rewrite" url="http://content.yudu.com/htmlReader/SomeString/SomeName/SomeFile.html" />
</rule>
4) Open your url: http://example.com/ebrochure/SomeBrochure and you should see page from yudu

Related

IIS Rewrite rule to edit content outgoing to proxy a HTTP image file?

I am trying to figure out what I would need to do for a rewrite rule to apply to tags if possible to append to the source to basically proxy the content of HTTP links.
Looks like google does it for its webmail and I need something similar for my self hosted webmail. I could ingore the Not Fully Secure warning but I want to try to finish it.
Unfortunately I dont remember how I did it in the past and I deleted the old folder to look at the web.config file that would have been in there.
This way I could look for image links with an image of http://example.com/image.png and make it https://example.org/proxy.php?url=http://example.com/image.png and then it would load the same image but now be secure. I have the php setup as needed to do this but now I need to figure out this outbound rewrite.
You can use rules like this.
<rule name="rule" preCondition="ISHTML">
<match filterByTags="A, Img" pattern="(.*)" />
<action type="Rewrite" value="https://example.org/proxy.php?url=http://{HTTP_HOST}{R:1}" />
</rule>
According to the law of image name and php page name, you can customize regular expressions to match the image you want to rewrite and the rewritten url

Redirect some HTTP URLs / AAMs to HTTPS

I have a client running SharePoint Server 2019 on IIS10, and they want to redirect http requests to https for one of a few Web apps/Alternate Access Mappings in their environment.
So, the web app http://intranet and http://intranet.domain.com should be redirected to https://intranet and https://intranet.domain.com respectively but http://mysites , http://mysites.domain.com and http://CentralAdmin:12345 should not.
Similarly, the internal SharePoint IIS sites like Security Token Service which are on host-named URLs like:
http://sp19-app:32843/SecurityTokenServiceApplication/securitytoken.svc
Should be left alone.
I have an internal CA-generated cert for https://intranet and a Comodo cert for https://intranet.domain.com in place, with working SharePoint AAMs and IIS bindings, both are working, a full range of URLs can be visited.
Most guides to the IIS URL rewrite, including Ruslan's
https://ruslany.net/2009/04/10-url-rewriting-tips-and-tricks/#redirect-https
and this well-written one:
https://www.namecheap.com/support/knowledgebase/article.aspx/9953/38/iis-redirect-http-to-https
and this one:
http://www.jppinto.com/2010/03/automatically-redirect-http-requests-to-https-on-iis7-using-url-rewrite-2-0/
grab all URLs on the site with (.*)
What I want to do is only grab and redirect the in-scope ones with this
(intranet)(.)*
or
^(http:\/\/intranet)(.)*
both of which I've tried, and while they don't redirect the critical service apps or MySites URLs, they don't consistently redirect the Intranet URLs either.
I've validated all of the affected URLs in regex101.com's testing panel, which they come up looking good in, but is there a possibility that either my regex isn't as hot as I think it is or URL rewrite uses a different implementation of it?
For example, under Conditions, I have dutifully added:
{HTTPS}
pattern: ^OFF$
which to my mind means "If OFF appears at the start of the string, at the end of the string", which is clearly nonsense.
My understanding from reading on the topic is that the purpose of Conditions is to create exceptions, and this one stops HTTPS requests being redirected to HTTPS, which is very sensible.
How it arrives at that using the rule I've added is not clear to me though.
The actual redirect to part is :
https://{HTTP_HOST}{REQUEST_URI}
which seems to be the most sensible, as SharePoint URLs will contain query strings and all sorts of stuff after the ? or &.
Screenshot of redirect rule
URL rewrite is configured on an IIS site-by-site basis, so maybe I'm worrying over nothing and I don't need to modify the regular expression. If that's the case, as I suspect it probably is, I suppose I can just leave it.
However, I hate having the solution but not knowing how it works, I'd much sooner be able to confidently write my rules and be certain they'll do precisely what I think they will and why.
You need to add another condition. You can try the rule below.
<conditions>
<add input="{HTTP_HOST}" pattern="^Intranet.(.*)$" />
<add input="{HTTPS}" pattern="^off$" />
</conditions>

IIS URL Rewrite with Incoming URL

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/

http://localhost:port always redirecting to https://localhost

I'm building a simple website in vs2015. I have IIS express selected as the hosting environment. I have tried multiple new projects and seem to be going around in circles, having installed and uninstalled iis-express 10 multiple times, and added and removed windows feature of iis also. When I launch a web project from vs2015, it used to open (without issue) a http://localhost:port (e.g. http://localhost:51898), but now continually redirects to https://localhost.
Any idea why?
It is not about Visual Studio, it is about Chrome.
This solution worked for me: Google Chrome redirecting localhost to https
the redirect will only happen with explict configuration and IIS or
asp.net will not automatically redirect .
check following config files and loo for any redirect settings
ApplicationHost.Config,All web.config files (C:\Windows\System32\inetsrv\config)
search for httpRedirect
e.g. <httpRedirect enabled="true" destination="https://localhost" />
check for urlrewrite configurations. a typical rule will be like this .so you can search for Redirect
<action type="Redirect" url="http://www.maindomain.com/{R:1}" />
</rule>
If you do not find these settings anywhere in your configuration,your application code is doing this.Check your code
In my situation it was caused by this piece of code:
services.Configure<MvcOptions>(options =>
{
options.Filters.Add(new RequireHttpsAttribute());
});
Anyway double check you startup.cs file. Maybe configurations there are part of a problem
in my case, it was a configuration i did on IIS for all my sites to load via https. The rewrite rule matched localhost as well and hence it redirects to https. I rewrote the redirect rule and it was ok.

ARR/URL Rewriter within a .net Web API application

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}");

Resources