IIS URL rewrite - reverse proxy - responding with 404 error - rest

basically i wanna to rewrite url using reverse proxy:
from:
http://www.xyz.in/eacc/api/fetchVendors
to
http://localhost:8080/eacc/api/fetchVendors
I have deployed my spring boot rest full web service application in tomcat under C:\Tomcat\apache-tomcat-9.0.7\webapps\eacc.
It contains many POST call like /eacc/api/fetchVendors, /eacc/api/users, /eacc/api/clients.. etc.
Now i wanna to expose this eacc rest application through IIS.
have main website configured called www.xyz.in.
added virtual directory under website (www.xyz.in) called /eacc.
physical path: C:\inetpub\wwwroot\eacc
below is web.config file.
When i try to hit one post call like www.xyz.in/eacc/api/fetchVendors, getting HTTP 404 server error.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
Requested URL: /eacc/api/fetchVendors
My web.config file for /eacc - virtual directory
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<httpRedirect enabled="false" />
<rewrite>
<rules>
<rule name="ReverseProxyInboundRule1" stopProcessing="true">
<match url="(.*)" />
<action type="Rewrite" url="http://localhost:8080/eacc/{R:1}" />
</rule>
</rules>
<outboundRules>
<rule name="ReverseProxyOutboundRule1" preCondition="ResponseIsHtml1">
<match filterByTags="A, Form, Img" pattern="^http(s)?://localhost:8080/eacc/(.*)" />
<action type="Rewrite" value="http{R:1}://www.xyz.in/{R:2}" />
</rule>
<preConditions>
<preCondition name="ResponseIsHtml1">
<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/(.+)" />
</preCondition>
</preConditions>
</outboundRules>
</rewrite>
</system.webServer>
</configuration>
Am new to IIS web server.have stuck with URL Rewrite reverse proxy pattern. have tried many pattern changes but no luck. Looking help from anyone.

For me, this worked on IIS:
Go to IIS root node >> ARR
Click "Server Proxy Settings" option
and enable it:

Inbound Rule:
Use Patters : ^eacc.*
Rewrite URL : http://localhost:8080/{R:0}
Outbound Rule:
Pattern : localhost:8080
Value : www.xyz.com
Also you need to Add Proxy settings (Application Request Routing Module - Server Proxy settings) :
(tick) Enable Proxy
(untick) REverse Rewrite in response headers

Related

Can I Redirect to HTTPS from HTTP if port 80 is closed

I have a react web application that I'm hosting on a Windows Server.
In IIS I created URL Rewrite rules. When I view the website from within our network the rewrite rules work and it redirects from HTTP to HTTPS.
However since port 80 is closed on the public side when i try to view the website in HTTP it never redirects and just times out. I'm assuming that's because it never actually hits the page since the port is closed so the redirect never kicks in.
Is there a way to still get the website to redirect to HTTPS with that port closed?
Here is how my web.config file looks:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
</customHeaders>
</httpProtocol>
<httpRedirect enabled="false" destination="https://mywebsitehere.com" />
<rewrite>
<rules>
<rule name="http to https" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://mywebsitehere.com/{R:1}" redirectType="SeeOther" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
The answer is No, in order for any form of HTTP redirection to work within the server, the server must be capable of getting the incoming connection HTTP request on port 80, It would then send a 3xx response to tell the browser to try again with a different URL, That URL would be an HTTPS URL. If the HTTP request is closed before the server gets it, naturally it can't do anything.

Redirect https to http without SSL - IIS 7

I recently moved my website from Wix.com to one that I created on GoDaddy (Windows server). Wix.com version used https, and the latter doesn't. Searching for the website on Google still lists the "https://*" version (which doesn't exist anymore) instead of listing the "http://" version.
Question 1:
How should I redirect visitors from https to http version without having to set up SSL on the new website? Adding this to web.config didn't help:
<rewrite>
<rules>
<rule name="Redirect to HTTP" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^ON$" />
</conditions>
<action type="Redirect" url="http://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
Question 2:
What should I do to make sure Google search shows the http version and not the https version?
Thanks!
1) It is not possible without SSL certificate. You can generate valid free certificate here: https://www.sslforfree.com/, add https into your IIS bindings and then your rule will work
2) In Google webmaster tools they have the option to change the address: https://support.google.com/webmasters/answer/83106?hl=en

asp.net MVC And I need to setup 301 redirects

I have a site moving from php to asp.net MVC And I need to setup 301 redirects for it so like www.mystoresitem.com/products/widget1name needs to redirect to www.mystoresitem.com/widget1name for 700+ different widgets how do I redirect this with out doing it for each product/widget.
First of all you need to be sure that you installed URL Rewrite module in your IIS
Then in your web.config just add this rules inside system.webServer section:
<rewrite>
<rules>
<rule name="Redirects to products">
<match url="^products/(.*)" />
<action type="Redirect" url="/{R:1}" />
</rule>
</rules>
</rewrite>
It will automatically redirect all your urls
www.mystoresitem.com/products/{productname} to www.mystoresitem.com/{productname}

In IIS 8.5, how do I map a sub-domain to an application within a site?

Currently I have an IIS 8.5 server with a URL of:
subdomain.domain.com/application_instance_name_1
Under a site called Portal Application there are 3 instances of the application, one for each customer.
I would like to create a subdomain per customer and direct it to their version of the application under the Site called Portal Application, for example, Customer 1 would type in:
customer_1_name.domain.com
and in IIS it would be directed to the site and Application below:
Sites/Portal Application/customer_1_application
This is my first time posting on here, I did find something that maybe relevant here but its for Apache not IIS.
IF you need further information please let me know.
Thanks
brian
1) You need to install URL Rewrite and ARR module for IIS
2) Enable ARR. On the Application Request Routing page, select Enable proxy
3) Create rewrite rule
<rewrite>
<rules>
<rule name="rewrite customer_1_name.domain.com" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern="^customer_1_name.domain.com$" ignoreCase="true" />
</conditions>
<action type="Rewrite" url="http://subdomain.domain.com/Portal Application/customer_1_application/{R:1}" />
</rule>
</rules>
</rewrite>
P.S. You might have problem with your resources(images,styles,css,js). Because your html might contains absolute paths to resources
You can check this post, when author is creating outbound rule for fixing relative urls https://blogs.iis.net/carlosag/setting-up-a-reverse-proxy-using-iis-url-rewrite-and-arr

Fixing 301 redirect rules to not be seen as not found IIS8.5 ASP.NET

I am getting 404 when trying to access domain like https://www.example.com I get 404.
I have the following rewrite rules:
<rules>
<rule name="Redirect-HTTP-HTTPS-IIS">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
</rule>
<rule name="CanonicalHostNameRule1">
<match url="(.*)"/>
<conditions>
<add input="{HTTP_HOST}" pattern="^example\.com$" negate="true"/>
</conditions>
<action type="Redirect" url="https://example.com/{R:1}"/>
</rule>
</rules>
Accessing https://www.example.com will get eventually to https://example.com. My problem is that some serves like Google webmaster tools validation can't verify the site because the page returns not found, although at the end it redirects to https://example.com.
http://example.com does show 301 redirect to https://example.com. It's only when I add www it doesn't show 301 redirect, although the server doe eventually redirects it to the right location.
How changes to the write rules I need to make so accessing https://www.example.com will be recognize as 301 redirect to https://example.com. I think that because of the multiple rules the page send not found.
Maybe there is a way to write it as a single rule that redirects 301 that includes both rules, so it will redirect URLs with HTTP or/and WWW to the one with HTTPS and non-WWW URLs.
Update: I inspected chrome Network and in the Status column, it say (canceled) for type Document and it shown on red. It might be due to IIS returning 404 because the HTTPS for domain with WWW is not certified. Is there any way around this?
Using IIS8.5 / ASP.NET 4.5
Thanks.
I needed to create an SSL certificate for the WWW version of the site as well. Once I did it, the redirection worked as intended.