IIS handling url requests for multiple applications within same webstie - iis

This is definitely out of my area of expertise so I hope I explain this well. We have a website and within that website we have 2 different applications with 2 different login pages. What would I have to do so that for example requests for app1.website.com and app2.website.com get's routed to the correct apps login page?
WebServer Screenshot

you could try this rule:
<rule name="app1 redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="app1.website.com" />
</conditions>
<action type="Rewrite" url="http://website.com/react1/app1/" logRewrittenUrl="true"/>
</rule>

Related

Url rewriting/routing on .Net Core with IIS and Cloudflare

A small introduction about the app's deployment & app in general:
We use .Net Core 6 MVC and is hosted in IIS. Additionally the application uses a domain which the actual website is hosted e.g. www.ExampleHost.com/ExampleApp.
Also we use Cloudflare to direct requests to a new domain for the website e.g. www.ExampleHost.com/ExampleApp -> www.Example-App.eu
Here is the problem, while the app works fine at www.ExampleHost.com/ExampleApp, if we enter www.Example-App.eu the directory of the app appears in the Url like www.Example-App.eu/ExampleApp in every request. That creates problem everywhere from returning Views to submitting Forms etc.
So an idea was to solve part of this problem by creating a web.config to configure URL Rewrite rules.
web.config
<rewrite>
<rules>
<rule name="RemoveExampleApp">
<match url=".*ExampleApp/(.*)" />
<conditions>
<add input="{REQUEST_METHOD}" matchType="Pattern" pattern="POST" ignoreCase="true" negate="true" />
</conditions>
<action type="Redirect" url="{R:1}"/>
</rule>
<rule name="RemoveExampleAppPost">
<match url=".*ExampleApp/(.*)" />
<conditions>
<add input="{REQUEST_METHOD}" matchType="Pattern" pattern="POST" ignoreCase="true" />
</conditions>
<action type="Rewrite" url="{R:1}" />
</rule>
</rules>
</rewrite>
But we still unable to perform POST requests.
Additionally, I read to another Stack Overflow post that it is possible to configure/fix that by of using routing instead of rewrite rules but we had no luck with that.
IIS URL Rewrite and .NET Core
We are open to any suggestions.
Thanks for your time.

IIS 10 - ULR Rewrite rule for stopping Image Hotlinking - when working also affects the domain host itself

Windows 2016 Server running IIS 10 with the URL Rewrite Module installed.
The servers are set up in a server Farm.
I've been messing around with this for the last 48 hours and cannot, for the life of me, figure out why it is not working as it is supposed to work.
I've looked at a video showing how to set it up and how it works, and I've mimicked what was done in the video, and nothing, still cannot get it to work.
This is what happens.
Using this code below will work; as you notice, it has the pattern="Pattern: "
However, the leading site that hosts the images has its images replaced with the stop-hotlinking.png image as well.
So, in theory, it works, but the hosting site has no access to its images to display.
If I remove (pattern="Pattern: "), it does not work.
To sum it up.
The below code will display the "stop-hotlinking.png" image on all outside sites, as well as the hosting site.
<rewrite>
<rules>
<rule name="STOP-Hot-Linking" enabled="true" stopProcessing="true">
<match url=".*\.(gif|jpg|png)$" />
<conditions>
<add input="{HTTP_REFERER}" pattern="Pattern: ^$" negate="true"/>
<add input="{HTTP_REFERER}" pattern="Pattern: ^https?://(www\.)?domain\.com/.*$" negate="true"/>
</conditions>
<action type="Rewrite" url="/graph/stop-hotlinking.png" />
</rule>
</rules>
</rewrite>
I even tried it with the pattern as this, and it will display the stop-hotlinking.png on all sites including the hosting site.
<add input="{HTTP_REFERER}" pattern="^http://(.*\.)?domain\.com/.*$" negate="true"/>
Below is the sample you could refer:
let's say I have 2 sites in my iis server and I would like to set a rule in the test site to not allow other domain sites to use images so I will set a URL rewrite rule in the test site.
test site index page contact:
<html>
<head>
<title>test.com title page</title>
</head>
<body>
<h2>test.com</h2>
<img src="http://test.com/img.jpg">
</html>
now i am trying to access image from the test site to the test2 site:
below is the rule i have set in my test site:
<rule name="Prevent Image Hotlinking" enabled="true" stopProcessing="true">
<match url=".*\.(jpg|jpeg|png|gif|bmp)$" />
<conditions>
<add input="{HTTP_REFERER}" pattern="^$" negate="true" />
<add input="{HTTP_REFERER}" pattern="^http://test.com/.*$" negate="true" />
</conditions>
<action type="Rewrite" url="/hotlink.jpg" logRewrittenUrl="true" />
</rule>
Note: hard refresh your page in bwroser if it does not work or you could try to open page in private mode.
I was assisted on another forum, and this was the issue.
I was testing the same image on multiple domains we own.
And that was the biggest problem, was the image would get cached, even when Google Tools was open, it would still cache it for whatever reason, we never could figure it out.
I changed to another image from the hosting site, and it started working.
We also found out that Google Chrome needed a referral meta tag in the head of the hosting sites page.
<meta name="referrer" content="origin">
Once all the above was taken care of and the following code in place. It started working.
<rule name="Prevent Image Hotlinking" enabled="true" stopProcessing="true">
<match url=".*\.(jpg|jpeg|png|gif|bmp)$" />
<conditions>
<add input="{HTTP_REFERER}" pattern="^https?://(www\.)?(?:DomainOne\.com|DomainTwo\.com|DomainThree\.com)/.*$" negate="true"/>
</conditions>
<action type="Rewrite" url="/graph/stop-hotlinking.png" logRewrittenUrl="true" />
</rule>
In the above, you will see there are multiple domains, this is to allow images to be hosted on their domains, and all other domains will get the STOP image.
This is completed.
I want to think Jalpa for trying to assist.
And gr8gonzo from the other forum for helping me out in this long venture.

IIS rewrite rules to enforce HTTPS and one of several canoncial domains

The site I'm looking after has multiple canoncial domains - e.g.
example.com
example.com.au
example.co.nz
as well as some 'other' domains that need to be redirected to one of the canoncial domains (e.g. example.us should go to example.com).
All sites should be accessed via HTTPS
Is it possible to write a concise rule for each canoncial domain that redirects the user to that domain iff
They're not on the canoncial domain (e.g. www.example.com, example.us) OR
The connection is not HTTPS
I think I can see how to do it wih multiple rules, but it will quickly become fiddly (so concise rules would be nicer)
I achieved it with the following (shoved multiple variables into the input with a # delimter):
<rule name="Redirect to example.co.nz" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTPS}#{HTTP_HOST}" pattern="(^OFF)|(^.*#www\.)" />
<add input="{HTTP_HOST}" pattern="^(www\.)?example.co.nz$" />
</conditions>
<action type="Redirect" url="https://example.co.nz/{R:1}" />
</rule>

IIS rule rewrite for query string

I have a URL that looks like
https://thesite.com/m/?pageName=profileSettings#notifications
I need to rewrite it to
https://thesite.com/m/?pageName=notificationSettings
I'm trying something like
<rule name="m_notifications" stopProcessing="true">
<match url="^m/(.*)" />
<conditions>
<add input="{QUERY_STRING}" pattern="pageName=profileSettings#notifications" />
</conditions>
<action type="Rewrite" url="pageName=notificationSettings" appendQueryString="False"/>
</rule>
This isn't working, no errors, just not making any changes. What am I missing?
Thanks
It is not possible to do a rewrite based on the hash string. Browser doesn't transmit the part after hash to the server.
It's called Fragment identifier and is client side only. It's not possible in any language unless you are using some browser implementation (or software) which would send that part of URL to the server.

conditional URL re-writes using IIS 7.5

We have a bilingual SharePoint website and would like to ensure that all French content is funnelled through our french domain, lets just call it _frenchdomain.com.
Languages variations in SharePoint are separated by folder structure, so in our case you can go to _http://englishdomain.com/en for English content and _http://englishdomain.com/fr for French content.
My question is how can I get IIS to recognize any instance of _http://englishdomain.com/fr/* and instead rewrite it as _http://frenchdomain.com/fr/*
<rule name="fr">
<match url="fr/.*"/>
<conditions>
<add input="{HTTP_HOST}" pattern="^frenchdomain.com$" negate="true" />
</conditions>
<action type="Redirect" url="http://frenchdomain.com/{R:0}" redirectType="Permanent"/>
</rule>

Resources