Redirect HTTP to HTTPS except one page with web.config

beyz

I would like to get all pages redirected from HTTP to HTTPS except one page (pagename.php) in the root directory, this page needs to work as HTTP (needs to be redirected back to HTTP). I currently have the following code to redirect from none-www to www and HTTP to HTTPS.

<rewrite>
      <rules>
        <rule name="Redirect to WWW" stopProcessing="true" >
          <match url="(.*)" />
          <conditions>
            <add input="{HTTP_HOST}" pattern="^www\." negate="true"/>
          </conditions>
          <action type="Redirect" url="https://www.{HTTP_HOST}{HTTP_URL}" redirectType="Permanent" appendQueryString="false" />
        </rule>
        <rule name="Redirect to HTTPS">
          <match url="(.*)" />
          <conditions>
            <add input="{HTTPS}" pattern="OFF"/>
          </conditions>
          <action type="Redirect" url="https://{HTTP_HOST}{HTTP_URL}" redirectType="Permanent" appendQueryString="false" />
        </rule>
      </rules>
      <outboundRules>
        <rule name="Add Strict-Transport-Security when HTTPS" enabled="true">
          <match serverVariable="RESPONSE_Strict_Transport_Security"
              pattern=".*" />
          <conditions>
            <add input="{HTTPS}" pattern="on" ignoreCase="true" />
          </conditions>
          <action type="Rewrite" value="max-age=31536000" />
        </rule>
      </outboundRules>
    </rewrite>

I need other role or exception in this role to rewrite back or redirect specific URLs to HTTP (There are only 2 URLs I need to get worked as HTTP and they are only the ones with .php page extension and all the other are different).

I would really appreciate your help in this.

Brandon Spilove

You need a condition with negate="true" to add the exception for your php files.

 <rule name="Redirect to HTTPS">
          <match url="(.*)" />
          <conditions>
            <add input="{HTTPS}" pattern="OFF"/>
            <add input="{URL}" pattern="(.*).php" negate="true" />
          </conditions>
          <action type="Redirect" url="https://{HTTP_HOST}{HTTP_URL}" redirectType="Permanent" appendQueryString="false" />
 </rule>

 <!--EDIT-->
 <rule name="Redirect to HTTP">
          <match url="(.*)" />
          <conditions>
            <add input="{HTTPS}" pattern="ON"/>
            <add input="{URL}" pattern="(.*).php" />
          </conditions>
          <action type="Redirect" url="http://{HTTP_HOST}{HTTP_URL}" redirectType="Permanent" appendQueryString="false" />
 </rule>

Este artigo é coletado da Internet.

Se houver alguma infração, entre em [email protected] Delete.

editar em
0

deixe-me dizer algumas palavras

0comentários
loginDepois de participar da revisão

Artigos relacionados

TOP lista

quentelabel

Arquivo