2

I was having problems trying to configure the mod rewrite over windows and II7: CakePHP 2.2.2 not working on Windows IIS7 but finally i could import the htaccess in order to create the web.config file for IIS7.

The thing is: Now that file has been created in cakephp folder and i can access to the main page BUT it has not been created inside app/ or app/webroot in which you can find 2 more .htaccess files.

Now, i can not access any other view than the main site, it shows a 404 page not found error and i am pretty sure that it is because it is not getting those .htaccess files on the web.config.

My cakephp web.config file looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
    <rewrite>
        <rules>
            <rule name="Imported Rule 1" stopProcessing="true">
                <match url="^$" ignoreCase="false" />
                <action type="Rewrite" url="app/webroot/" />
            </rule>
            <rule name="Imported Rule 2" stopProcessing="true">
                <match url="(.*)" ignoreCase="false" />
                <action type="Rewrite" url="app/webroot/{R:1}" />
            </rule>
        </rules>
    </rewrite>
</system.webServer>
</configuration>

Although the CakePHP documentation tells you to add a different code (which makes the views work but no styles are loaded. And the home page don't work.) http://book.cakephp.org/2.0/en/installation/advanced-installation.html#url-rewrites-on-iis7-windows-hosts

When trying to access a CSS file from the URL i get this message:

Missing Controller

Error: CssController could not be found.

Error: Create the class CssController below in file: app\Controller\CssController.php

<?php
class CssController extends AppController {

}

Any idea? Working with Cakephp over windows is driving me crazy...

2 Answers 2

7

I should mention that my response is an improvement on the solution posted here: http://www2.palomar.edu/pages/sphillips/cakephp-with-iis-7-rewrite-rules-in-a-sub-folder/

A simpler and more flexible fix would be to get rid of /{Path_To_CakePHP_Directory}/ altogether, including the forward slash (/). By keeping the paths relative, your project folder becomes a lot more mobile. Here's what the web.config would look like:

 <configuration>
   <system.webServer>
     <rewrite>
       <rules>
         <clear/>
         <rule name="Imported Rule 0" stopProcessing="true">
           <match url="^(img|css|files|js)(.*)$"></match>
           <action type="Rewrite" url="app/webroot/{R:1}{R:2}" appendQueryString="false"></action>
         </rule>
         <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="app/webroot/" />
         </rule>
         <rule name="Imported Rule 3" stopProcessing="true">
           <match url="(.*)" ignoreCase="false" />
           <action type="Rewrite" url="app/webroot/{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>
   </system.webServer>
 </configuration>
1
  • Are rule 1 and rule 4 supposed to be exactly the same?
    – NikG
    Feb 4, 2015 at 16:02
2

Ok, finally i get it work using this web.config i found on this site: http://www2.palomar.edu/pages/sphillips/cakephp-with-iis-7-rewrite-rules-in-a-sub-folder/

I just changed the /{Path_To_CakePHP_Directory}/ for /.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.