Windows IIS7上的Htaccess和CakePHP 2

问题描述 投票:2回答:2

我试图在Windows和II7上配置mod重写时遇到问题:CakePHP 2.2.2 not working on Windows IIS7但最后我可以导入htaccess以便为IIS7创建web.config文件。

事情是:现在该文件已经在cakephp文件夹中创建,我可以访问主页但是它还没有在app /或app / webroot中创建,你可以在其中找到2个.htaccess文件。

现在,我无法访问除主站点之外的任何其他视图,它显示404页面未找到错误,我很确定这是因为它没有在web.config上获取这些.htaccess文件。

我的cakephp web.config文件如下所示:

<?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>

虽然CakePHP文档告诉您添加不同的代码(这使得视图工作但没有加载样式。并且主页不起作用。)http://book.cakephp.org/2.0/en/installation/advanced-installation.html#url-rewrites-on-iis7-windows-hosts

当尝试从URL访问CSS文件时,我收到以下消息:

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 {

}

任何的想法?在Windows上使用Cakephp让我发疯...

.htaccess cakephp web-config cakephp-2.0 cakephp-2.2
2个回答
7
投票

我应该提一下,我的回答是对此处发布的解决方案的改进:http://www2.palomar.edu/pages/sphillips/cakephp-with-iis-7-rewrite-rules-in-a-sub-folder/

一个更简单,更灵活的修复方法是完全删除/ {Path_To_CakePHP_Directory} /,包括正斜杠(/)。通过保持路径相对,您的项目文件夹变得更加移动。这是web.config的样子:

 <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>

2
投票

好的,最后我使用这个web.config让我的工作在我的网站上找到:http://www2.palomar.edu/pages/sphillips/cakephp-with-iis-7-rewrite-rules-in-a-sub-folder/

我刚刚更改了/ {Path_To_CakePHP_Directory} / for /。

© www.soinside.com 2019 - 2024. All rights reserved.