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?
Related
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}" />
I need redirect only main domain with web config redirect rules, and redirect an specific subdomain, but not redirect any other subdomain:
What I need:
if www.maindomain.com -> redirect to www.maindomain.com/index.html
if www.maindomain.com/specificSubdomain -> redirect to www.maindomain.com/specificSubdomain/index.html
if www.maindomain.com/whateverOther -> not redirect, goes to www.maindomain.com/whateverOther
Actually I have this code, but It not works appropiately:
<rule name="redi" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="www.maindomain\.com/index.html$" negate="true" />
<add input="{HTTP_HOST}" pattern="www.maindomain\.com/specificSubdomain/$" negate="true" />
<add input="{HTTP_HOST}" pattern="www.maindomain\.com" negate="false" />
<add input="{HTTP_HOST}" pattern="www\.maindomain\.com/$" negate="true" />
</conditions>
<action type="Redirect" url="https://www.maindomain.com/index.html" redirectType="Found"/>
</rule>
I have probed different combinations but any works, ideas? Thanks!
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>
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>
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>