I can't figure out how to get my web.config deployment transformation to work for a rewrite rule. I've tried the following and it ignores it.
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<system.webServer>
<rewrite xdt:Transform="Replace">
<rules>
<rule name="Force HTTPS On Login/Register" stopProcessing="true">
<match url="Account/Login(.*)|Register(.*)" ignoreCase="true" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:0}" redirectType="Permanent" />
</rule>
<rule name="Force HTTPS Off" stopProcessing="true">
<match url="((Account/Login(.*))|(Register(.*)))" negate="true" ignoreCase="true" />
<conditions>
<add input="{HTTPS}" pattern="^ON$" ignoreCase="true" />
</conditions>
<action type="Redirect" url="http://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
I use SlowCheetah to transform my web.config for production. I originally tried what you tried, but found that I had to add an empty
<rewrite>
<rules />
</rewrite>
to the base web.config
and then write a transform like
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect to HTTPS" stopProcessing="true" xdt:Transform="Insert">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
(that is a redirect transform, but I think the same principal should apply).
Note xdt:Transform="Insert" to insert a new node into the skeletal <rules /> in the base config file.
Related
My requirement is to need redirect url for particular domain.So i decided
to use rewrite map but what ever i tried below that will apply for all domain i have. Its not apply to particular domain.
Let me example more deeply. Suppose i have 3 domains on same IIS instance
www.abc.com
www.xyz.com
www.eee.com
In domain www.abc.com the url www.abc.com/legal should be redirected to www.abc.com/privacy.
Like above i have plenty of redirects url need to implement for the same domain.
Below listed things i had tried
<!--Test snippet 1-->
<rewrite>
<rules>
<rule name="Redirect rule1 for Redirects" enabled="true" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern=".*www.abc.com.*" />
<add input="{ABCRedirects:{REQUEST_URI}}" pattern="(.+)" />
</conditions>
<action type="Redirect" url="{C:1}" appendQueryString="false" />
</rule>
</rules>
<rewriteMaps configSource="abc-rewritemaps.config" />
</rewrite>
<!--Test snippet 2-->
<rewrite>
<rules>
<rule name="Redirect rule1 for Redirects" enabled="true" stopProcessing="true">
<match url=".*www.abc.com.*" />
<conditions>
<add input="{HTTP_HOST}" pattern=".*www.abc.com.*" />
<add input="{ABCRedirects:{REQUEST_URI}}" pattern="(.+)" />
</conditions>
<action type="Redirect" url="{C:1}" appendQueryString="false" />
</rule>
</rules>
<rewriteMaps configSource="abc-rewritemaps.config" />
</rewrite>
<!--Test snippet 3-->
<rewrite>
<rules>
<rule name="Redirect rule1 for Redirects" enabled="true" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{ABCRedirects:{REQUEST_URI}}" pattern=".*www.abc.com.*" />
</conditions>
<action type="Redirect" url="{C:1}" appendQueryString="false" />
</rule>
</rules>
<rewriteMaps configSource="abc-rewritemaps.config" />
</rewrite>
<!--My Rewrite map-->
<rewriteMaps>
<rewriteMap name="ABCRedirects">
<add key="/legal" value="/privacy" />
<add key="/good" value="/bad" />
<add key="/hi" value="/bye" />
<add key="/no" value="/not" />
<add key="/123" value="/321" />
</rewriteMap>
</rewriteMaps>
Above all code i tried is applied for all domain, I cant able to limit its for only www.abc.com alone.
How to limit rewrite maps for particular domain?
I need to redirect http to https on external network (internet), but on local network such as 192.168.1.100 works on http. I used this following configuration:
<system.webServer>
<rewrite>
<rules>
<rule name="HTTPS force" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
You can add an additional condition "host shouldn't match 192.168.1.100".
Your rule should be like that:
<rule name="HTTPS force" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
<add input="{HTTP_HOST}" pattern="^192.168.1.100$" negate="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
</rule>
On a VPS using Windows 2006 R2 I am wanting to edit the web.config file so that all pages found within several subfolders are redirected from http to https.
I've found this suggestion below and what I would like to know is how to list the specific folders where this rewrite rule would then be applied.
The subfolders are:
/secure1/
/secure2/
/admin1/
/admin2/
Any help and advice would be greatly appreciated :)
<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>
</rules>
</rewrite>
</system.webServer>
How about something like this?
<rule name="test" stopProcessing="true">
<match url="(secure1|secure2|admin1|admin2).*" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
</rule>
Got the information from this url if you would like to learn more:
https://forums.iis.net/t/1176994.aspx?Https+Redirect+for+certain+folders+sections+only
I have a azure web app which uses custom domain from godaddy.
I got the SSL certificate from namecheap.com and applied binding to
both mathanka.com and www.mathanka.com
When i enter manually it works fine. I used web.config with below mentioned rules.
<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}/{R:1}" redirectType="Permanent" appendQueryString="false" />
</rule>
</rules>
</rewrite>
<staticContent>
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="1.00:00:00" />
</staticContent>
</system.webServer>
but its not redirecting to https://
url : mathanka.com
Please guide me the solution and step to take.
Thanks.
<?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>
</rules>
</rewrite>
</system.webServer>
</configuration>
This is the copy\paste from here.
I'm trying to force HTTPS via a web.config URL rewrite rule for a URL which includes a path.
eg http://my.domain.com/folder must be forced to use https://my.domain.com/folder
I'd also like to force HTTPS for all pages on their relative paths
eg http:// my.domain.com/folder/page.aspx forced to https:// my.domain.com/folder/page.aspx
This is what I have:
<rewrite>
<rules>
<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>
Try this URL rewrite rule:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="HTTP/S to HTTPS Redirect" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{SERVER_PORT_SECURE}" pattern="^0$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Check your casing and the type of quotes you are using. Also, the 2nd input method is invalid - the pattern isn't valid a regex. This rule works for what you want:
<rule name="Redirect to HTTPS" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
</rule>