How do I make URL rewrite work with web.Release.config transform?
Transformation will only happen if you put proper xdt
attributes on the elements that need to be transformed. Try adding an xdt:Transform
attribute to your release config:
<system.webServer xdt:Transform="Replace"> <!-- the rest of your element goes here --></system.webServer>
That will tell the transformation engine that the entire system.webServer
element from Web.config
needs to be replaced with the one from Web.Release.config
.
The transformation engine will silently ignore any elements that do not have xdt
attributes.
Obligatory link to MSDN.
Another way to go would be to put in a rewrite condition that negates if you are on localhost:
<conditions> <add input="{HTTP_HOST}" pattern="localhost" negate="true"/></conditions>
<system.webServer> <rewrite> <rules xdt:Transform="Replace"> <clear /> <rule name="Redirect HTTP to HTTPS" stopProcessing="true"> <match url="(.*)" /> <conditions logicalGrouping="MatchAll" trackAllCaptures="false"> <add input="{HTTP_HOST}" pattern="localhost(:\d+)?" negate="true" /> <add input="{HTTP_HOST}" pattern="127\.0\.0\.1(:\d+)?" negate="true" /> <add input="{HTTPS}" pattern="OFF" /> </conditions> <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="SeeOther" /> </rule> </rules> </rewrite></system.webServer>