CakePhp on IIS: How can I Edit URL Rewrite module for SSL Redirects

Posted by AdrianB on Server Fault See other posts from Server Fault or by AdrianB
Published on 2011-11-16T20:11:30Z Indexed on 2011/11/17 1:54 UTC
Read the original article Hit count: 531

Filed under:
|
|

I've not dealt much with IIS rewrites, but I was able to import (and edit) the rewrites found throughout the cake structure (.htaccess files). I'll explain my configuration a little, then get to the meat of the problem.

So my Cake php framework is working well and made possible by the url rewrite module 2.0 which I have successfully installed and configured for the site. The way cake is set up, the webroot folder (for cake, not iis) is set as the default folder for the site and exists inside the following hierarchy

inetpub
-wwwroot
--cakePhp root
---application
----models
----views
----controllers
----WEBROOT  // *** HERE ***
---cake core
--SomeOtherSite Folder

For this implementation, the url rewrite module uses the following rules (from the web.config file) ...

    <rewrite>
        <rules>
        <rule name="Imported Rule 1" stopProcessing="true">
        <match url="^(.*)$" ignoreCase="false" />
        <conditions logicalGrouping="MatchAll">
                    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
        </conditions>

        <action type="Rewrite" url="index.php?url={R:1}" appendQueryString="true" />

        </rule>

        <rule name="Imported Rule 2" stopProcessing="true">
          <match url="^$" ignoreCase="false" />
          <action type="Rewrite" url="/" />
        </rule>
        <rule name="Imported Rule 3" stopProcessing="true">
          <match url="(.*)" ignoreCase="false" />
          <action type="Rewrite" url="/{R:1}" />
        </rule>
        <rule name="Imported Rule 4" stopProcessing="true">
          <match url="^(.*)$" ignoreCase="false" />
          <conditions logicalGrouping="MatchAll">
                    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
          </conditions>
          <action type="Rewrite" url="index.php?url={R:1}" appendQueryString="true" />
        </rule>
        </rules>
    </rewrite>

I've Installed my SSL certificate and created a site binding so that if i use the https:// protocol, everything is working fine within the site. I fear that attempts I have made at creating a rewrite are too far off base to understand results. The rules need to switch protocol without affecting the current set of rules which pass along url components to index.php (which is cake's entry point).

My goal is this-> Create a couple of rewrite rules that will [#1] redirect all user pages (in this general form http://domain.com/users/page/param/param/?querystring=value ) to use SSL and then [#2} direct all other https requests to use http (is this is even necessary?).

[e.g.
    http://domain.com/users/login , 
    http://domain.com/users/profile/uid:12345 , 
    http://domain.com/users/payments?firsttime=true]
 ]

to all use SSL

[e.g.
    https://domain.com/users/login , 
    https://domain.com/users/profile/uid:12345 , 
    https://domain.com/users/payments?firsttime=true]
 ]

Any help would be greatly appreciated.

© Server Fault or respective owner

Related posts about iis7

Related posts about ssl