URL Rewrite two different scenarios - url

I want to achieve the below:
When the URL is https://www.example.com/ it should be redirected to https://www.otherdomain.com/
When the URL is https://www.example.com/images/anything, it should stay in the same domain https://www.example.com/images/anything.
How can I do this?
I got the following for 1:
<rule name="Rule1">
<match url=".*"/>
<conditions>
<add input="{HTTP_HOST}" pattern="https://www.example.com/"/>
</conditions>
<action type="Rewrite" url="https://www.otherdomain.com/>
</rule>
How to create a rule for point 2?

Related

Issue with URL Rewriting - IIS & MVC

I trying to build a rewrite rule to "Permanent Redirect" of a PHP page to MVC site. here is the URL of PHP site
/Home/new-age-xxx.php & url of MVC site to which I want user to redirect "/home/new-age-xxx"
here is my URL rewriting rule
<rule name="Imported Rule 1-599" stopProcessing="true">
<match url="^home\new/-age/-xxx\.php$" ignoreCase="false" />
<action type="Redirect" url="/home/new-age-xxx" appendQueryString="false" redirectType="Permanent" />
</rule>
It is not redirecting to /home/new-age-xxx, even i tried to move it to other urls like /login/index
Any suggestion?
Thanks
You could use a bewlo url rewrite rule to redirect one site url to another site:
e.g:
Request URL: http://www.sample2.com/home/new-age-123.php
Redirect url:http://www.example.com/home/new-age-123
<rule name="reg redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{REQUEST_URI}" pattern="/home/new\-age\-([0-9]{1,3}).php$" />
</conditions>
<action type="Redirect" url="http://www.example.com/home/new-age-{C:1}" appendQueryString="false" />
</rule>
To learn more about url rewrite module you could refer the bewlo link:
Creating Rewrite Rules for the URL Rewrite Module
Regards,
Jalpa

Web requesting forwarding to another domain

I have a site "MySite" setup in my IIS with the below HTTP bindings,
www.example.com:80
www.example.net:80
www.example.org:80
I need to temporarily redirect all users coming to www.example.net to www.example.com/product.
Any ideas how to achieve this ?
Hi Siva Sankar Gurram,
You could use below url rewrite rule to redirect url www.example.net to www.example.com/product by using below url rewrite rule in iis:
<rule name=".net to .com" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www.example.net$" />
</conditions>
<action type="Redirect" url="http://www.example.com/product" redirectType="Temporary" />
</rule>
Note: If you did not installed Url rewrite module first install it.

IIS Rewrite and reverse proxy for multiple applications

I have an IIS 10 with a website configured on that. There are multiple Applications underneath that website.
MyWebsite/app1 - MyWebsite/app2 - MyWebsite/app3
I Have another server(let's call it EndServer) hosting 3 websites on 3 different ports.
well, now what I wanna do is using IIS as a reverse proxy to redirect and MASK the application 1 to one of those websites in 2nd server and application 2 to another one.
at the end, Users will enter https://mywebsite/app1 and they will see the contents of website 1 in the Endserver.
Note: it is important for me that end Users see the URL like as https://mywebsite/app1/
how shall I edit the Rule below:
<rewrite>
<rules>
<rule name="ReverseProxyInboundRule1" stopProcessing="true">
<match url="(.*)" />
<action type="Rewrite" url="http://endserver:8052/{R:1}" />
<conditions trackAllCaptures="true">
</conditions>
</rule>
</rewrite>
Thanks
A.
According to your description, I suggest you could try to use below url rewrite rule.
<rule name="ReverseProxyInboundRule1" stopProcessing="true">
<match url="(.*)" />
<conditions trackAllCaptures="true">
<add input="{URL}" pattern="^/app1/(.*)" />
</conditions>
<action type="Rewrite" url="http://endserver:8052/{C:1}" />
</rule>
<rule name="ReverseProxyInboundRule2" stopProcessing="true">
<match url="(.*)" />
<conditions trackAllCaptures="true">
<add input="{URL}" pattern="^/app2/(.*)" />
</conditions>
<action type="Rewrite" url="http://endserver:8053/{C:1}" />
</rule>
Thanks for your answer.
I got same error. as you see below /App1 is missing in the URL after localhost:Port
localhost:8888/assets/styles/Custom.css?m=1549903616.0
I believe the trouble is with rewriting the response URL. I don't know who can I add the missing part in URL.
Regards.

IIS URL redirection - igonre match all for some URLs

I had to change previous URL pattern to something else. Earlier URL pattern was
www.testdomain.com/hotels/"city" and it changed to www.testdomain.com/hotel-"city"
Below is the redirection I have used that for.
<rule name="cityChange" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^hotels/(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="www.testdomain.com" />
</conditions>
<action type="Redirect" url="www.testdomain.com/hotel-{R:1}"appendQueryString="false" redirectType="Temporary" />
</rule>
Now I have another issue which is another URL I have used for the site is also redirecting to different one. That URL is,
www.testdomain.com/hotels/'city'/'name'-'street'-'postalcode'
Since I have used a wildcard for /hotels/'city' to /hotel-'city' it changes above URL as
www.testdomain.com/hotel-'city'/'name'-'street'-'postalcode'
as well. But that URL is not valid in the site and I do not want to replace "/" from "-" there.
How can I exclude this URL pattern from that wild card which I have mentioned above?
Thanks in advance.
Can't be sure about that but did you try to add parentheses, like that ?
<match url="^(hotels)/(.*)" />
We did that for ou specific wildcard redirect :
<rule name="modeles-en" enabled="true" stopProcessing="true">
<match url="^(modeles-en)/(.*)" ignoreCase="true" />
<action type="Redirect" url="/models/{R:2}" redirectType="Permanent" />
</rule>
Hope it helps !

How to rewrite part of the URL and then attach the remaining?

For example, rewrite from www.example.com/foo/123 to www.example.com/bar/123
In web.config I have something like:
<rewriteMap name="TestRM">
<add key="/foo/" value="/bar" />
</rewriteMap>
<rule name="TEST" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{TestRM:{PATH_INFO}}" pattern="(.+)" />
</conditions>
<action type="Redirect" url="http://www.example.com{C:1}" appendQueryString="false" redirectType="Temporary" />
</rule>
With this is place, www.example.com/foo can be redirected to www.example.com/bar, but no www.example.com/foo/123 to www.example.com/bar/123
Anything I need to add to make the last part attached?
One of the strategy you can use is to use regex and separate the URL Parts.
For example URL: www.example.com/foo/123
Regex: ^(/foo)(/.*)? will separate out /foo and /123 or /123/3434/ or anything after /foo
Then you can craft the redirect URL as Such:
{HTTP-HOST}/bar{R:2}

Resources