Web requesting forwarding to another domain - asp.net-mvc

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.

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

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 !

Missing www in my url (on cellphone) causing "This connection is not private" ASP.NET MVC

I've just published my website, and I realized missing www in my (BUT ONLY ON CELLPHONE) url causing this issue:
It is interesting fact that if I type url without www on my computer or laptop website is working fine, but if I type url without www on my cellphone, that is message that I'm getting (screenshot above).
So
"https://example.com" // causing issue (because there is no www)
"https://www.example.com" // works fine on my cellphone
I must say that I've tried editing web.config file, and I added this rule which should redirect all non www to www url, so my web.config looks like this:
<rewrite>
<rules>
<rule name="Canonical Host Name" 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="HTTP to HTTPS redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="https://{HTTP_HOST}/{R:1}" />
</rule>
</rules>
</rewrite>
But I do not know what it's about, cuz it's causing issue only on cellphones looks like..
So any kind of help would be great!
Thanks
If you are using https://, all your urls must be with https://. If you will use http:// this will cause errors. Additionaly, you have to setup certificate for both https://www.sample.com and https://sample.com
And check your web.config you use http insted of https

IIS URL Rewrite multiple parameters

I am really confused about the URL rewrite interface. I dont understand what i need to do.
I have an url as:
www.example.com/diretory/subdirectory/index.html?param1=1&param2=2&param3=2&param4=7
I want to hide this url in a <a>-href tag, which displays "Example Tag".
When the url is requested it should rewrite it to
www.example.com/program/location/year/vacancie
I allready tried this:
<system.webServer>
<rewrite>
<rules>
<rule name="ProgramRewrite" patternSyntax="ECMAScript" stopProcessing="true">
<match url="\?([^/]+)&([^/]+)&([^/]+)&([^/]+)" />
<action type="Rewrite" url="www.example.com/program/location/year/vacancie" logRewrittenUrl="true" />
<conditions>
</conditions>
</rule>
</rules>
</rewrite>
</system.webServer>
In the URL Rewrite Interface the Test Pattern said it is working and gets:
?param1=1&param2=2&param3=2&param4=7
param1=1
param2=2
param3=2
param4=7
I checked the log url rewrite as well, but in my logs it is not shown.
2017-03-20 16:29:24 192.168.253.146 GET /diretory/subdirectory/index.html param1=1&param2=2&param3=2&param4=7 88 - 192.168.253.146 Mozilla/5.0+(Windows+NT+10.0;+Win64;+x64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/56.0.2924.87+Safari/537.36 - 304 0 0 4
ps: the urls are not working and only for illustrative purpose.
The match URL only matches the URL and does not take the querystring into account. You will need to add a condition for this. Also do you want to rewrite this (so the server internally executes the new URL) or redirect (so the server will request the browser to go to the new URL and URL changes in address bar). In case you want to rewrite you should not add the domain again, in case you want to redirect add http:// as well. Assuming a rewrite is what you want use below rule:
<rule name="ProgramRewrite" patternSyntax="ECMAScript" stopProcessing="true">
<match url="(.*)" />
<action type="Rewrite" url="/program/location/year/vacancie" logRewrittenUrl="true" />
<conditions>
<add input="{QUERY_STRING}" pattern="([^/]+)&([^/]+)&([^/]+)&([^/]+)" />
</conditions>
</rule>

Resources