【问题标题】:Htaccess and CakePHP 2 on windows IIS7Windows IIS7 上的 Htaccess 和 CakePHP 2
【发布时间】:2012-09-11 22:48:38
【问题描述】:

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

问题是: 现在该文件已在 cakephp 文件夹中创建,我可以访问主页 BUT 它尚未在 app/app/webroot 中创建> 您可以在其中找到另外 2 个 .htaccess 文件。

现在,我无法访问除主站点之外的任何其他视图,它显示 404 page not found 错误,我很确定这是因为它没有在 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


    【解决方案1】:

    我应该提到我的回复是对此处发布的解决方案的改进: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>
    

    【讨论】:

    • 规则 1 和规则 4 应该完全相同吗?
    【解决方案2】:

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

    我刚刚将 /{Path_To_CakePHP_Directory}/ 更改为 /

    【讨论】:

      猜你喜欢
      • 2012-09-11
      • 2015-02-08
      • 1970-01-01
      • 1970-01-01
      • 2010-12-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-15
      相关资源
      最近更新 更多