Looking for url rewrite using IIS - proxy

https://my-public-url.com is just a public url and it is pointing to my public ip server (20.23.45.67:443)
my dev url : https://my-Dev-url.local (it points to the web application in ex: 10.99.11.20:1562)
my QA url : https://my-QA-url.local (it points to the web application in ex: 10.99.11.20:2678)
my UAT url: https://my-UAT-url.local (it points to the web application in ex: 10.99.11.20:3456)
When I click on the url https://my-public-url.com/Dev it should redirect to my dev url
When I click on the url https://my-public-url.com/QA it should redirect to my Qa url
When I click on the url https://my-public-url.com/UAT it should redirect to my UAT url
Is it possible to achieve the above requirement using IIS proxy rules, if yes please help me how to do that
Thanks in Advance

According to your description, I suggest you could refer to below rewrite rule.
<rewrite>
<rules>
<rule name="Reverse Proxy to Dev" stopProcessing="true">
<match url="^Dev/(.*)" />
<action type="Rewrite" url="https://my-Dev-url.local/{R:1}" />
</rule>
<rule name="Reverse Proxy to QA" stopProcessing="true">
<match url="^QA/(.*)" />
<action type="Rewrite" url="https://my-QA-url.local/{R:1}" />
</rule>
<rule name="Reverse Proxy to UAT " stopProcessing="true">
<match url="^UAT/(.*)" />
<action type="Rewrite" url="https://my-UAT-url.local/{R:1}" />
</rule>
</rules>
</rewrite>
More details, you could refer to beblow article:
https://learn.microsoft.com/en-us/iis/extensions/url-rewrite-module/reverse-proxy-with-url-rewrite-v2-and-application-request-routing

Finally, this works for me.
<rule name="Rewrite to Dev page">
<match url="^Dev(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^my-public-url.com$" />
</conditions>
<action type="Rewrite" url="http://my-Dev-url.local/{R:1}" />
</rule>`
When I click on https://my-public-url.com/Dev it is redirecting to my local url

Related

Need to redirect folder URL /media/default to Page URL /media/default/image

IIS rewrite rule is not working.
I have tried adding the following rule for redirect but it's not working. Can anyone help me on this as I am not familiar with rewrite rules.
<rule name="test" patternSyntax="ExactMatch" stopProcessing="true">
<match url='/media/default' />
<action type="Redirect" url="/media/default/image" />
<conditions>
</conditions>
</rule>

Rewrite rule for windows server + IIS and Cakephp 3.x

I want to deploy my site to Windows hosting from linux. On Linux server everything working as expected. but few things are not working on windows server.
Please let me know what changes i need to do in web.config
My file system is:
-src
-webroot
--css
--about.html
--index.php
--contact.php
Now how i can access about.html directly http://www.example.com/about.html and similarly for other php files too.
these are rule i am using for now:
<rewrite>
<rules>
<rule name="Exclude direct access to webroot/*"
stopProcessing="true">
<match url="^webroot/(.*)$" ignoreCase="false" />
<action type="None" />
</rule>
<rule name="Rewrite routed access to assets(img, css, files, js, favicon)"
stopProcessing="true">
<match url="^(assets|font|fonts|img|images|css|files|js|favicon.ico)(.*)$" />
<action type="Rewrite" url="webroot/{R:1}{R:2}"
appendQueryString="false" />
</rule>
<rule name="Rewrite requested file/folder to index.php"
stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<action type="Rewrite" url="index.php"
appendQueryString="true" />
</rule>
</rules>
</rewrite>

IIS 8.0 Directory HttpRedirect

Is there a way in IIS to redirect the following request:
http://mysite/report1/img/logo.png to http://mysite/myapplication/report1/images/logo.png for ALL images in the img directory without having to explicitly map them individually?
Additional requirement- I have THOUSANDS of reports on a drive mapped to the 'report1' virtual directory- each with their own 'img' directory- so there is no reasonable way to use IIS manager to map those directories individually either.
I'm looking to see if there is some way to add a wildcard (or other) HttpRedirect in the IIS server web.config file to correctly map all the images for all the reports. I tried:
<add wildcard="*res/img/" destination="/reporter/content/images/reportimages" />
But that seemed to have no effect.
EDIT: Some more research shows that using the URL Rewrite module might work... but so far I haven't gotten it to work.
My rule looks like this (in web.config):
<rules>
<rule name="Redirect rule1 for ImageRedirect">
<match url=".*" />
<conditions>
<add input="{ImageRedirect:{REQUEST_URI}}" matchType="Pattern" pattern="/res/img/(.+)" ignoreCase="true" negate="false" />
</conditions>
<action type="Redirect" url="{HTTP_HOST}/reporter/content/reporterimages/{C:1}" appendQueryString="false" />
</rule>
</rules>
You were on the right track using the URL Rewrite module.
The most simple rule in your case would be:
<rule name="Rewrite images" stopProcessing="true">
<match url="^/report1/img/(.+)$" />
<action type="Rewrite" url="/myapplication/report1/images/{R:1}" />
</rule>
It does check if the requested url matches ^/report1/img/(.+)$ and if yes, trigger a rewrite to your new folder.
If you want to use a Redirect instead:
<rule name="Redirect images" stopProcessing="true">
<match url="^/report1/img/(.+)$" />
<action type="Redirect" url="/myapplication/report1/images/{R:1}" />
</rule>
(If you don't specify it, by default a Redirect is permanent (301))

ISAPI PHP REWRITE

A friend is having me figure out a way to modrewrite on his windows server. He is running IIS 6 and Isapi is about the only thing I can find. I am not familiar with it and have read some of the documentation, but can't quite wrap my head around it. He is wanting to rewrite these URLS to make them clean
www.domain.com/cat.php?CTGID=####
and
www.domain.com/pp.php?ID=##
How would I go about rewriting these two URLS to make them Clean in ISAPI. I have installed it on the Windows Server and do I put these rules in IISF.ini in his website folder or put these codes in the master IISF file? Any Help would be greatly appreciated!
Rewrite rules go in a web.config file or in the ApplicationHost.config.
As described in http://learn.iis.net/page.aspx/465/url-rewrite-module-configuration-reference/
Examples
<rewrite>
<rules>
<rule name="Force WWW" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^example.com$" />
</conditions>
<action type="Redirect" url="http://www.example.com/{R:0}" redirectType="Permanent" />
</rule>
<rule name="Redirect from blog">
<match url="^blog/([_0-9a-z-]+)/([0-9]+)" />
<action type="Redirect" url="article/{R:2}/{R:1}" redirectType="Found" />
</rule>
<rule name="Rewrite to article.aspx">
<match url="^article/([0-9]+)/([_0-9a-z-]+)" />
<action type="Rewrite" url="article.aspx?id={R:1}&title={R:2}" />
</rule>
</rules>
</rewrite>
For IIS, if the ISAPI_Rewrite module is installed, $_SERVER["IIS_UrlRewriteModule"] is set and contains the version number of the module. So you can check for the existence of this server variable.

Redirect URL in IIS 7.5

I want to all www domain to naked via IIS Rewrite engine. There are many domains pointing to same application.
Here is my rule :
^(www.)(.*)$
Action Type : Redirect
Redirect URL : {R:2}
Redirect Type : Permanent
When i test pattern for www.xxx.com
R:0 => www.stackoverflow.com R:1=> www. R:2 => www.stackoverflow.com
and that is fine.
What is wrong? And also should I include "http://" ?
Something like ^(www\.)(.+)$ should work when matching the http_host, but it might be better to specify the domain. From what I know of IIS (not much) and what it says on the net, something like:
<rewrite>
<rules>
<rule name="Redirect www.xxx.com to xxx.com" patternSyntax="ECMAScript" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www\.domain\.com$" />
</conditions>
<action type="Redirect" url="http://domain.com/{R:0}" />
</rule>
</rules>
</rewrite>
Oh, you said for any domain. If you want to make sure it ends in .com it should be something like
^(www\.)(.+)(\.com)$ against HTTP_HOST
.. oh, if you do that you need to back reference, so try something like this:
<rewrite>
<rules>
<rule name="Redirect www.domain.com to domain.com" patternSyntax="ECMAScript" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www\.(.+)$" />
</conditions>
<action type="Redirect" url="http://{C:1}/{R:0}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
The c:1 is a back reference

Resources