IIS rewrite rule not working in live environment IIS rewrite rule not working in live environment azure azure

IIS rewrite rule not working in live environment


Your rule should be like that:

<rule name="http to https" stopProcessing="true">    <match url=".*" />    <conditions>        <add input="{HTTPS}" pattern="^OFF$" />        <add input="{REQUEST_URI}" pattern="/backoffice" negate="true" />    </conditions>    <action type="Redirect" url="https://www.WEBSITENAME.com{R:0}" /></rule>

This rule will exclude requests with /backoffice path.

Also for issue of mixing content you need to fix your paths for css/js/images to relatives. Example:

<img src="/path/to/your/image.jpg"/>

Another way to fix mixed content is create outbound rule, which will change your output HTML (replace http: to https:):

<rewrite>  ...  <outboundRules>    <rule name="Rewrite external references to use HTTPS" preCondition="IsHTML">      <match filterByTags="Script, Link, Img, CustomTags" customTags="HTML5Tags" pattern="^http://(.*)$" />      <action type="Rewrite" value="https://{R:1}" />    </rule>    <preConditions>      <preCondition name="IsHTML">        <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />      </preCondition>    </preConditions>    <customTags>      <tags name="HTML5Tags">        <tag name="Video" attribute="src" />      </tags>    </customTags>  </outboundRules></rewrite>


Using the previous answer as a starting point, i made a few minor changes, to use HTTP_HOST rather than REQUEST_URI for the pattern negation and it works.

<system.webServer>    <rewrite xdt:Transform="InsertIfMissing">        <rules>            <rule name="http to https" stopProcessing="true">                <match url=".*" />                <conditions>                    <add input="{HTTPS}" pattern="^OFF$" />                    <add input="{HTTP_HOST}" pattern="^backoffice\.WEBSITENAME\.com$" negate="true" />                </conditions>                <action type="Redirect" url="https://www.WEBSITENAME.com/{R:0}" />            </rule>        </rules>    </rewrite></system.webServer>