how to write an iis config rule to stop redirect of .asmx - redirect

I have this section in my web config to redirect http requests to https excluding .asmx references
<rewrite>
<rules>
<rule name="HTTP to HTTPS redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
<add input="{URL}" pattern="^.aspx" ignoreCase="true" negate="true" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="https://{HTTP_HOST}/{R:1}" />
</rule>
</rules>
</rewrite>
This redirects http requests OK but web services don't work - I get
<head><title>Document Moved</title></head>
<body><h1>Object Moved</h1>This document may be found here</body>
with the error genereated at
System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
at PCS_Spe
cification.wsEntrant.WSEntrant.refresh

<add input="{URL}" pattern="^.aspx" ignoreCase="true" negate="true" />
You want to stop redirect of .asmx, but in your rewrite rule, your parameter is .aspx, so you need to change the parameter to .asmx.
Or you can also try the following rewrite rules:
<rule name="RewriteAllButasmx" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{URL}" negate="true" pattern="\.asmx$" />
</conditions>
<action type="Rewrite" url="https://{HTTP_HOST}/{R:1}" />

Related

IIS RewriteMaps to new URL including WWW and HTTPS

I have the following Rule in my RewriteRules
<rule name="New URL redirects">
<match url=".*"/>
<conditions>
<add input="{OldUrls:{REQUEST_URI}}" pattern="(.+)"/>
</conditions>
<action type="Redirect" url="{C:1}" appendQueryString="false"/>
</rule>
in my RewriteMaps i have the following
<rewriteMap name="OldUrls">
<add key = "/SomeOldUrl" value = "/New/ShinyUrl" />
</rewriteMap>
I want to make sure that the new url is using www and https as part of the redirect, how do i add all of this into one rule?
You could try below rule:
<rule name="Force WWW and SSL" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^[^www]" />
<add input="{HTTPS}" pattern="off" />
<add input="{HTTPS}" pattern="www.sample1.com" negate="true" />
<add input="{OldUrls:{REQUEST_URI}}" pattern="(.+)" />
</conditions>
<action type="Redirect" url="https://www.sample1.com/{C:1}" appendQueryString="true" redirectType="Permanent" />
</rule>
<rewriteMap name="OldUrls">
<add key="/s2" value="/s3" />
</rewriteMap>
</rewriteMaps>

IIS Rewrite for single query string to SEO version

I am trying for hours to get the following IIS rewrite to work:
Incoming URL:
https://example.com/services/control/status?Id=SO1234567
Expected output:
https://example.com/orders/detail/SO1234567
IIS Rewrite Rule:
<rule name="Custom rewrite rule" patternSyntax="ExactMatch" stopProcessing="true">
<match url="^services/control/status\?Id=(SO|so){1}([0-9]*)" />
<action type="Rewrite" url="/orders/detail/{R:0}" appendQueryString="false" logRewrittenUrl="true" />
</rule>
Additional information:
I am running a single web site in IIS.
1 web applications for an API under this web site.
Angular files within the web site.
Angular rules:
<rule name="Angular Routes" stopProcessing="false">
<match url=".*" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_URI}" pattern="^/(api)" negate="true" />
</conditions>
<action type="Rewrite" url="/" />
</rule>
Complete Rewrite section:
<rewrite>
<rules>
<clear />
<rule name="Angular Routes" stopProcessing="false">
<match url=".*" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_URI}" pattern="^/(api)" negate="true" />
<add input="{REQUEST_URI}" pattern="^/(marketplace)" negate="true" />
</conditions>
<action type="Rewrite" url="/" />
</rule>
<rule name="Custom rewrite rule" patternSyntax="ExactMatch" stopProcessing="true">
<match url="^services/control/status\?Id=(SO|so){1}([0-9]*)" />
<action type="Rewrite" url="/orders/detail/{R:0}" appendQueryString="false" logRewrittenUrl="true" />
</rule>
</rule>
</rules>
</rewrite>
As far as I know, the url pattern will not match the query string. If you want to get the query string value, you should use rewrite condition.
Details, you could refer to below rule:
<rule name="QueryStringRue" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{QUERY_STRING}" pattern="^Id=([0-9a-zA-Z]*)" />
</conditions>
<action type="Redirect" url="https://example.com/orders/detail/{C:0}" />
</rule>

Redirect to admin subdomain only when path ends with '/umbraco/'

I have a situation where our client runs their Umbraco based website with load balancing, and we have the following rule that redirects request to all of these servers to the primary domain "https://www.ourclient.co.uk".
This is the code for that redirect:
<!-- Canonicalize all domains to a single domain -->
<rule name="SEO - http canonical redirect" stopProcessing="true" enabled="false">
<match url="(.*)"/>
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^www\.ourclient\.co\.uk" negate="true"/>
<add input="{HTTP_HOST}" pattern="^admin\.ourclient\.co\.uk" negate="true"/>
<add input="{HTTP_HOST}" pattern="^01-live\.ourclient\.co\.uk" negate="true"/>
<add input="{HTTP_HOST}" pattern="^02-live\.ourclient\.co\.uk" negate="true"/>
<add input="{HTTP_HOST}" pattern="^03-live\.ourclient\.co\.uk" negate="true"/>
<add input="{HTTP_HOST}" pattern="^04-live\.ourclient\.co\.uk" negate="true"/>
</conditions>
<action type="Redirect" url="https://www.ourclient.co.uk/{R:1}"/>
</rule>
Now what I need to achieve is any request to https://www.ourclient.co.uk/umbraco/ is redirected to https://admin.ourclient.co.uk/umbraco/ but for the life of me I just can't get anything to work.
Any help towards a solution will be very welcome, as would any corrections to my post.
Just add a new rule.
<rules>
<rule name="SEO - http canonical redirect">
... your old stuff ... but exclude the admin.yourclient.com/umbraco (!)
</rule>
<rule name="redirectUmbracoToAdminSite">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^yourclient\.com$" negate="true" />
<add input="{REQUEST_URI}" matchType="Pattern" pattern="^umbraco" ignoreCase="true" negate="false" />
</conditions>
<action type="Redirect" url="http://admin.yourclient\.com/{R:1}" />
</rule>
</rules>

Url rewrite is not redirecting to https

I have a url rewrite in my web.config that is supposed to redirect some urls to https while ignoring some other urls.
Here is what I currently have:
<rewrite>
<rules>
<rule name="Redirect to HTTPS">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
<add input="{HTTP_HOST}" pattern="localhost" negate="true" />
<add input="{HTTP_HOST}" pattern="^.qa.mysite.com" negate="true" />
<add input="{HTTP_HOST}" pattern="dev1.qa.mysite.com" negate="false" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Redirect" url="https://{SERVER_NAME}/{R:1}" redirectType="SeeOther" />
</rule>
</rules>
</rewrite>
I works as expected by not redirecting localhost and all *.qa.mysite.com urls. It also redirects dev1.qa.mysite.com to https as expected.
The issue is that I want dashboard.mysite.com to be automatically redirected https, and I cannot figure out how to make that work.
If I add,
<add input="{HTTP_HOST}" pattern="dashboard.mysite.com" negate="false" />
, it does not work.
Any idea what am I missing?

Web.config redirect one domain to non-https folder and another domain to https folder

I have a domain alias for my site. I would like to know how to redirect requests for domainA.ext to https://domainA.ext/folderA and requests for domainB.ext to http://domainB.ext/folderB
Presently I have the following rule to redirect all http requests to https but it redirects ALL requests to https:
<rule name="Redirect to https" stopProcessing="true">
<match url="(.mydomain.ext*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://mydomain.ext}" redirectType="Permanent" />*
</rule>
It is Windows server 2008, but my cms is in PHP.
I can't think of something more simple than 4 different rules.
The 2 first ones for domainA.ext:
<rule name="Check path folderA" stopProcessing="true">
<match url="^folderA" negate="true" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern="domainA\.ext$" />
</conditions>
<action type="Redirect" url="https://domainA.ext/folderA/" />
</rule>
<rule name="Check SSL for domainA" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern="domainA\.ext$" />
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://domainA.ext/folderA/" />
</rule>
1st rule: if the path doesn't start with folderA, then it redirects to https://domainA.ext/folderA/
2nd rule: if HTTPS is off, it redirects to https://domainA.ext/folderA/
And the 2 next ones for domainB.ext:
<rule name="Check path folderB" stopProcessing="true">
<match url="^folderB" negate="true" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern="domainB\.ext$" />
</conditions>
<action type="Redirect" url="http://domainB.ext/folderB/" />
</rule>
<rule name="Check no SSL for domainB" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern="domainB\.ext$" />
<add input="{HTTPS}" pattern="^ON$" />
</conditions>
<action type="Redirect" url="http://domainB.ext/folderB/" />
</rule>
1st rule: if the path doesn't start with folderB, then it redirects to http://domainB.ext/folderB/
2nd rule: if HTTPS is on, it redirects to http://domainB.ext/folderB/