Web.Release.Config Rewrite URL Exclusion - iis-7

I have found the following code which will redirect all my traffic to https:
<system.webServer>
<rewrite xdt:Transform="Insert">
<rules>
<rule name="RedirectToHTTPS" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://{SERVER_NAME}/{R:1}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
Is it possible to add an "exclusion" to this rule somehow?
I would like a particular path not to be redirected if possible
For example I would like everything below http://www.example.com/desktopmodules/ not to redirect.
Can it be done please?

You can add a rule above it which matches your exclusion pattern, ensuring that the stopProcessing="true" is set on the rule, but with no action:
<system.webServer>
<rewrite xdt:Transform="Insert">
<rules>
<!-- Prevent redirection of URLs matching this pattern -->
<rule name="ExcludeRedirectToHTTPS" stopProcessing="true">
<match url="^desktopmodules.*" />
<action type="None" />
</rule>
<rule name="RedirectToHTTPS" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://{SERVER_NAME}/{R:1}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>

Related

ASP.Net - HTTP to HTTPS Rewrite Module Not Working When the Character '&' Exists in the URL String

My URL HTTP to HTTPS rewrite does not work when there is the character '&' in the URL.
A 410 page not found results.
An example that results in a 410 is...
http://curtainsmadesimple.co.uk/1062/Rapture-&-Wright/Rapture-&-Wright-Collection-Roomshots
OR
http://www.curtainsmadesimple.co.uk/1062/Rapture-&-Wright/Rapture-&-Wright-Collection-Roomshots
However if the '&' is replaced by 'and' in the above URLs the page loads correctly.
I have two rules to rewrite HTTP to HTTPS. One is where there is a non www and the other if there is a www
<rule name="CanonicalHostNameRule1">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www\.curtainsmadesimple\.co\.uk$" negate="true" />
</conditions>
<action type="Redirect" url="https://www.curtainsmadesimple.co.uk/{R:1}" />
<rule name="Redirect to HTTPS">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
</rule>
Can anyone tell me why I am getting this issue?
Thanks in advance.
It will work I believe. This is working for me.
<rewrite>
<rules>
<clear />
<rule name="Redirect to https" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
</rule>
</rules>

Setting up URL Rewrite rule

I've a rewrite role in my web.config, and it's redirect to mydomain.com/de.
But now I will replace the action de/{R:1} with the user language, where I can get from {HTTP_ACCEPT_LANGUAGE}. But this is a string of language and looks like fr-CH,**fr**;q=0.8,en;q=0.6,de;q=0.4,de-CH;q=0.2/
So it's there possibility to get the out only the **fr** of this string?
Thanks for any help.
This is my role:
<rule name="mydomain.com" stopProcessing="true" >
<match url="(.*)" />
<conditions>
<add input="{URL}" pattern="/en/|/de/" negate="true" />
</conditions>
<action type="Redirect" url="de/{R:1}" />
</rule>
In the past i have used the following rule to redirect to a language based page
<rewrite>
<rules>
<rule name="RedirectToLang" enabled="true" stopProcessing="true">
<match url=".*" />
<action type="Redirect" url="{R:0}/{HTTP_ACCEPT_LANGUAGE}" appendQueryString="true" />
<conditions>
<add input="{HTTP_ACCEPT_LANGUAGE}" pattern=".+" />
</conditions>
</rule>
</rules>
</rewrite>

Redirection from "https://www" to "https://"

We have the ASP.NET application hosted as Azure WebApp and configured the domain from GoDaddy. We bought SSL for non-www domain. We used the following redirection rule:
<rewrite>
<rules>
<rule name="Redirect to Example.com">
<match url="(.*)"/>
<conditions>
<add input="{HTTP_HOST}" pattern="^(?!^Example.com)" />
</conditions>
<action type="Redirect" url="https://Example.com/{R:1}"/>
</rule>
<rule name="Redirect to https">
<match url="(.*)"/>
<conditions>
<add input="{HTTPS}" pattern="Off"/>
<add input="{REQUEST_METHOD}" pattern="^get$|^head$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}"/>
</rule>
</rules>
</rewrite>
Is there a way to add another rule to redirect request to "https://www" to "https://"?
Thanks,
Jay
I had a similar challenge with my Windows hosting since I have a wildcard cert and host a few subdomains. Here's the web.config I put together, give it a shot and let me know! It seems to work great for me, but my site is extremely simple.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<clear />
<rule name="Redirect to https" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
</rule>
<rule name="remove www" stopProcessing="true">
<match url="(.*)" ignoreCase="true" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www\.YourDomain\.com$" />
</conditions>
<action type="Redirect" url="https://YourDomain.com/{R:0}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>

Rewriting sitemap.xml url - asp.net web.config

I know in htaccess but how can I rewrite url of sitemap using web.config Rules property. I have tried following ways, but none worked
<rule name="sitemap URL" patternSyntax="ECMAScript" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^/sitemap.xml$" /> - Not working
<add input="{HTTP_HOST}" pattern="^domain.com/sitemap.xml$" /> - Not working
<add input="{HTTP_HOST}" pattern="^www.domain.com/sitemap.xml$" /> - Not working
</conditions>
<action type="Rewrite" url="foldername/sitemaps/sitemap-a.xml" />
</rule>
also tried
<rule name="sitemap URL" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^.+\.(local|www)?(domain).+\.(?:xml)$" />
<action type="Rewrite" url="foldername/sitemaps/sitemap-a.xml" />
</rule>
This worked for me.
<rule name="SiteMap" patternSyntax="Wildcard" stopProcessing="true">
<match url="sitemap.xml" />
<action type="Rewrite" url="sitemap.ashx" appendQueryString="false" />
</rule>

How do I redirect all but a single url to https in ASP.Net?

I have the following code in my web.config:
<rewrite>
<rules>
<rule name="Redirect HTTP to HTTPS" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}"
redirectType="SeeOther" />
</rule>
</rules>
</rewrite>
I would like to redirect everything EXCEPT for http://www.mysite.com/manual to https.
How would I modify the above to allow this?
It should be ok with adding the following code in your conditions tag
<add input="{REQUEST_URI}" negate="true" pattern="^/manual/*" ignoreCase="true" />

Resources