IIS redirect in web.config - iis-8

Hi I would like to find out how to url rewrite.
so when the user type http://test-qa or http://test-qa.domain.com then it will redirect https url: https://test.qa.domain.com
my IISBinding
http://test-qa
http://test-qa.domain.com
Here that i have so far.
<rewrite>
<rules>
<rule name="test" stopProcessing="true">
<match url="http://test-qa" />
<action type="Redirect" url="https://test.qa.domain.com" appendQueryString="false" />
</rule>
</rules>
</rewrite>

If you prefer wildcard and assuming you only have these two bindings
<rules>
<rule name="HTTP to HTTPS" enabled="true" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<conditions>
<add input="{HTTPS}" pattern="off" />
</conditions>
<action type="Redirect" url="https://test.qa.domain.com/{R:1}" redirectType="Temporary" />
</rule>
</rules>

Related

Reverse Proxy to HTTP server via IIS with SSL

web.config
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="ReverseProxyApi" stopProcessing="true">
<match url="api/(.*)" />
<action type="Rewrite" url="http://localhost:3000/{R:1}" />
</rule>
<rule name="ReverseProxyClient" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{CACHE_URL}" pattern="^(.+)://" />
</conditions>
<action type="Rewrite" url="{C:1}://localhost:3001/{R:1}" />
<serverVariables>
<set name="HTTP_SEC_WEBSOCKET_EXTENSIONS" value="" />
</serverVariables>
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
I have successfully created a reverse proxy from http://localhost:9999 to my http://localhost:3000 (NestJS api server) and http://localhost:3001 (NextJS client server) using the above config in rewrite url.
My problem is that I am geting an error when I tried to bind https://localhost:8888 to the same site. I made sure that the https url is in the site bindings. I also have a self signed ssl certificate with it.
This is the error I am getting:
As you can see here https://localhost:8888 is in the site bindings
This is self signed certificate that I am using
I have no idea what is wrong in my setup. I have tried to restart both the website and the whole IIS server but I am getting the same error.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="ReverseProxyApi" stopProcessing="true">
<match url="api/(.*)" />
<action type="Rewrite" url="http://localhost:3000/{R:1}" />
</rule>
<rule name="ReverseProxyClient" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{CACHE_URL}" pattern="^(.+)://" />
</conditions>
<action type="Rewrite" url="{MapProtocol:{C:1}}://localhost:3001/{R:1}" />
<serverVariables>
<set name="HTTP_SEC_WEBSOCKET_EXTENSIONS" value="" />
</serverVariables>
</rule>
</rules>
<rewriteMaps>
<rewriteMap name="MapProtocol">
<add key="https" value="http" />
<add key="wss" value="ws" />
</rewriteMap>
</rewriteMaps>
</rewrite>
</system.webServer>
</configuration>
This web config works. I think what was wrong in my previous config is that https://localhost:8888 is redirected to https://localhost:3001 which does not exist (because of the {C:1}).
With this new config:
ws:// or wss:// -> ws://
http:// or https:// -> http://

Getting 404 Not found when refresh page in Vue JS

I'am getting error "404 Not found" when i refresh any page in my Vue JS application hosted in Azure Web APP (IIS Server) except the default web page index.html
I'am already adding this rewrite configuration in my web.config according to VueJs offical docs :
<rule name="Handle History Mode and custom 404/500" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="/" />
</rule>
This is my web.conf file:
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Handle History Mode and custom 404/500" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{​​​​​​​REQUEST_FILENAME}​​​​​​​" matchType="IsFile" negate="true" />
<add input="{​​​​​​​REQUEST_FILENAME}​​​​​​​" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="/" />
</rule>
<rule name="redirect all requests" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{​​​​​​​REQUEST_FILENAME}​​​​​​​" matchType="IsFile" negate="true" pattern="" ignoreCase="false" />
</conditions>
<action type="Rewrite" url="index.html" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
the `router.js` file have this conf :
const router = new VueRouter({
mode: 'history',
routes: [...]
})
Any idea to resolve that ?
Regards
EDIT :
Just ADD pm2 serve /home/site/wwwroot --no-daemon --spa , in
Azure Portal > App Service > Configuration > Application Setting
Azure APP Service based on Linux , don't need to use web.config
BR.
Since I came here from top google results, and kind of kicked of my journey to get results I want to post this here in hopes it will help someone in future.
I was trying to host my Vue#3 app on local IIS to test if things work before I exchange it in production.
I am actually rewriting Vue#2 app in Vue#3, and for Vue#2 following any of these 3 links would yield success:
https://gist.github.com/AngeloAnolin/6b19d22220b27a545e10f5fa672072fa
https://www.linkedin.com/pulse/hosting-vue-js-spa-build-microsoft-iis-zainul-zain
https://dnilvincent.com/blog/posts/host-vuejs-app-on-iis
However, in Vue#3 this is a bit of overkill and will throw http error 500.19 - internal server error. Changing content of web.config with following content would yield success:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Handle History Mode and custom 404/500" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="/" />
</rule>
</rules>
</rewrite>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
That's it basically. Good luck with everything :D

Rewrite rule to redirect from one language to other except certain pages

In my below mentioned redirection rule I am redirecting website "fr-ca" language to "en" language except onboarding pages. That means urls should not redirect to "en" language if the urls contains onboarding pages. But it is always redirecting to "en". Please let me know what is wrong in my rule. Thanks in advance.
<rule name="Site-fr-CA to en" stopProcessing="false">
<match url="^fr-ca(.*)$" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(.*)www.TestSite.com(.*)$" ignoreCase="false" />
<add input="{HTTP_HOST}" pattern="^fr-ca/onboarding(.*)$" negate="true" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="/en{R:1}" />
</rule>
</rules>
The issue is the HTTP_HOST in your second condition. Use PATH_INFO instead:
<rule name="Site-fr-CA to en" stopProcessing="false">
<match url="^fr-ca(.*)$" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(.*)www.TestSite.com(.*)$" ignoreCase="false" />
<add input="{PATH_INFO}" pattern="^/fr-ca/onboarding(.*)$" negate="true" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="/en{R:1}" />
</rule>

Shibboleth Errors When Authenticating Through a Reverse Proxy

I am attempting to configure a new Shibboleth based SP that will authenticate via my SAML iDP (Duo Access Gateway).
My Shibboleth SP is running behind an IIS-based reverse proxy that rewrites the URL's to the SP. The SP and Shibboleth itself are running on Apache on a Windows Server.
The issue with this configuration is that my SP (Shibboleth) believes it's running on, let's call it "sp.mycompany.com". However my iDP is delivering the assertion to the reverse proxy address "proxy.mycompany.com" which then rewrites the request to "sp.mycompany.com". This results in Sibboleth throwing the error "SAML message delivered with POST to incorrect server URL" to the user, and logging an error of "POST targeted at (https://proxy.mycompany.com/Shibboleth.sso/SAML2/POST), but delivered to (http://sp.mycompany.com/Shibboleth.sso/SAML2/POST)" in the Shibd log.
I've been searching but have only found fixes for this that apply to different situations than mine.
EDIT: Reverse Proxy Config Added Below
`<configuration>
<system.webS<rewrite>
<outboundRules>
<clear />
<rule name="Duo" enabled="true" stopProcessing="true">
<match filterByTags="None" pattern="^Shibboleth.sso/(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="true" />
<action type="Rewrite" value="https://proxy.mycompany.com/{R:0}" />
</rule>
<rule name="ReverseProxyOutboundRule1" preCondition="ResponseIsHtml1" enabled="true">
<match filterByTags="A, Form, Img" pattern="^http(s)?://sp.mycompany.com/(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="true" />
<action type="Rewrite" value="http{R:1}://proxy.mycompany.com/{R:2}" />
</rule>
<preConditions>
<preCondition name="ResponseIsHtml1">
<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
</preCondition>
</preConditions>
</outboundRules>
<rules>
<clear />
<rule name="Duo" enabled="true" stopProcessing="true">
<match url="^dag/(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Rewrite" url="https://duo.mycompany.com/{R:0}" appendQueryString="true" logRewrittenUrl="true" />
</rule>
<rule name="ReverseProxyInboundRule1" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Rewrite" url="http://sp.mycompany.com/{R:1}" logRewrittenUrl="true" />
</rule>
</rules>
<rewriteMaps>
<rewriteMap name="test" />
</rewriteMaps>
</rewrite>
<httpRedirect enabled="false" destination="https://proxy.mycompany.com/dag" />
</system.webServer>
</configuration>`

IIS 7.5: Removing trailing slash doesn't work

We have ASP.NET application and set in web.config:
<rewrite>
<rules>
<rule name="RemoveTrailingSlashRule1" stopProcessing="true">
<match url="(.*)/$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="{R:1}" />
</rule>
</rules>
</rewrite>
But, the trailing slash is still there.
Also, I've tried to use the code in Global.asax.cs file:
protected void Application_BeginRequest(Object sender, EventArgs e)
{
if (HttpContext.Current.Request.Url.ToString().Contains("http://concert.local/elki/"))
{
HttpContext.Current.Response.Status = "301 Moved Permanently";
HttpContext.Current.Response.AddHeader("Location", Request.Url.ToString().Replace("http://concert.local/elki/", "http://concert.local/elki"));
}
}
But, it doesn't work as well.
The specific is "elki" is subfolder in the project and has its own web.config file that looks as following:
<configuration>
<system.webServer>
<defaultDocument>
<files>
<add value="Sections.aspx" />
</files>
</defaultDocument>
<httpRedirect enabled="true" destination="/elki" httpResponseStatus="Permanent" />
</system.webServer>
</configuration>
How to make it work, that is remove trailing slash?
try removing it from the web.config ?
<rewrite>
<rules>
<rule name="Remove trailing slash" stopProcessing="true">
<match url="^([^.]+)/$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="{R:1}" />
</rule>
</rules>
</rewrite>