【问题标题】:mod_rewrite 404 Errormod_rewrite 404 错误
【发布时间】:2013-03-01 08:47:18
【问题描述】:

我一直在查看有关修复 mod_rewrite 以用于 CakePHP(以及 CakePHP 文档)的帖子和一些 Google Groups 资料,但我似乎无法让 mod_rewrite 正常工作。

CakePHP 安装正常,我得到主页,我得到: 然后我创建了一个模型 app/Model/Format.php:

<?php

    /**
     * File: app/Model/Format.php
     *
     * Format Model
     */
    class Format extends AppModel
    {
        var $name = 'Format';

        // <hasMany>
        var $hasMany = array(
                                'DVD' => array('className' => 'DVD')
                            );
    }

    ?>

一个带有方法的Controller app/Controller/FormatsController.php:

function index()
    {           // Ignore Format -related- data
        $this->Format->recursive = 0;

        // Get all formats from the database that have a status of '1'
        $formats = $this->Format->find('all', array(
                                                        'conditions' => array('Format.status' => '1')
                                                    ));

        // Save the Formats in a variable for display from the View
        $this->set('formats', $formats);
    }

最后是一个 View app/View/Formats/index.ctp:

<?php
    // File: app/Views/Formats/index.ctp
?>

<div class='formats index'>

    <table>
        <thead> 
            <tr>
                <th> Format Name</th>
                <th> Description </th>
                <th> Actions </th>
            </tr>
        </thead>
        <tbody>
            <?php

            ?>
        </tbody>
    </table>

</div>

我在 cakephp 根目录、app 根目录、webroot 目录中的 .htaccess 文件都与 CakePHP 建议 @http://book.cakephp.org/1.3/en/The-Manual/Developing-with-CakePHP/Installation.html 匹配。

我还将 RewriteBase [path to my app dir] 添加到每个 .htaccess 文件中,因为 Google 小组中的某个人说它对他们有用。

但是,每当我尝试加载“cakecms/Formats/index”时,我都会得到:

有人对我缺少什么有任何想法吗? 我今天在一台新笔记本电脑上,而这是在我的上一台笔记本电脑上工作的。我必须错过一些东西......

【问题讨论】:

  • 您是否按照book.cakephp.org/1.3/en/The-Manual/Developing-with-CakePHP/… 中的说明设置了AllowOverride All
  • 是的。我的默认目录是这样设置的: Options FollowSymLinks AllowOverride All Options +MultiViews #Order deny,allow #Deny from all 另外,'apachectl configtest' 返回“Syntax OK”。

标签: cakephp mod-rewrite configuration http-status-code-404


【解决方案1】:

如果您有 url 重写问题,您通常会在默认主页上收到一条错误消息,而您没有,因此这可能不是问题。您应该检查的网址是cakecms/formats(注意小写“f”)。 “索引”部分对于索引操作是可选的。

【讨论】:

  • 还要确保在您的 app/Config/core.php 中打开了调试功能
  • cakecms/formats 返回与上面的屏幕截图相同的页面和相同的错误。我当前的调试级别设置为 2,但我仍然只是得到“未找到”。我从未使用过 CakePHP 的 DebugKit;我想我会安装它,看看它是否能提供任何新见解。
【解决方案2】:

[已解决]

终于弄清楚我错过了什么。 我从未更改过默认值

<Directory [DocumentRoot] />
....
</Directory>

我的 httpd.conf 文件中的目录。

虽然我在更具体的 &lt;Directory...&gt; 列表中允许覆盖,但我在默认 DocumentRoot 列表中拒绝它们。 一旦我在 httpd.conf 的默认 DocRoot 目录中更改为 AllowOverride All,Cake/Apache URL 路由就可以完美运行。

【讨论】:

    猜你喜欢
    • 2010-11-06
    • 1970-01-01
    • 2013-05-31
    • 1970-01-01
    • 2010-12-01
    • 2023-03-14
    • 1970-01-01
    • 2014-10-20
    • 1970-01-01
    相关资源
    最近更新 更多