Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Url Rewrite HTTPS -> HTTP except certain page (IIS 7)

Only one page, and all dependencies (css, jpg etc), is to be SSL for now. I created the following rewrite:

  <rule name="Not Appointment Form 4.1 SSL" enabled="true" patternSyntax="ECMAScript" stopProcessing="true">
      <match url=".*" negate="false" />
      <conditions>
          <!-- check if https is on -->
          <add input="{HTTPS}" pattern="on" />

          <!-- I'm only interested in the aspx files -->
          <add input="{PATH_TRANSLATED}" pattern=".aspx$" /> 

          <!-- anything BUT the page to be secured -->
          <add input="{PATH_INFO}" pattern="page-to-be-secured.aspx" negate="true" /> 
      </conditions>
      <action type="Redirect" url="http://mydomain{PATH_INFO}" redirectType="Permanent" />
  </rule>   

I've tried putting the name of the page in the match url (negate="false") and still doesn't work.

I've tested each individual condition and they all work individually, but as a whole it's not redirecting to the none-HTTPS page.

like image 744
chris_eyekiller Avatar asked Mar 15 '26 06:03

chris_eyekiller


1 Answers

A simple way would be:

<rule name="Not Appointment Form 4.1 SSL" stopProcessing="true">
    <match url="^(.*)\.aspx$" />
    <conditions>
        <add input="{R:1}" pattern="page-to-be-secured" negate="true" />
        <add input="{HTTPS}" pattern="^ON$" />
    </conditions>
    <action type="Redirect" url="http://{HTTP_HOST}/{R:0}" />
</rule>

The rule is applied to every requested url ending with .aspx. If the first back reference ({R:1}) corresponding to the part before .aspx doesn't match page-to-be-secured and is using HTTPS, then the redirect is triggered.

like image 156
cheesemacfly Avatar answered Mar 16 '26 22:03

cheesemacfly



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!