【问题标题】:CakePHP MAMP mod_rewrite not working?CakePHP MAMP mod_rewrite 不工作?
【发布时间】:2014-06-03 01:56:34
【问题描述】:

最近一直在研究 PHP 和 Cake 框架,并尝试在我的 MacBook 上使用带有 MAMP 的 Cake 2.4.7 建立一个新项目。

我想使用 DebugKit 插件,在安装过程中它表明我的 mod-rewrite 配置不正确,因为似乎没有加载 DebugKit 的样式。我觉得我已经尝试了人们建议让它工作的一切,但似乎没有任何效果。

这是我迄今为止在论坛上找到并尝试过的所有东西的列表,如果有人有其他可以尝试的东西,我将非常感激!

  1. git clone https://github.com/cakephp/debug_kit.git 在创建debug_kitapp/Plugin 目录中

  2. app/Config/bootstrap.php 中添加/取消注释CakePlugin::load('DebugKit');

  3. app/Config/core.php 中添加了Configure::write('debug', 2);

  4. app/View/Layouts/default.ctp 中删除了 ?php echo $this->element('sql_dump'); ?>

  5. 在项目根目录中添加.htaccess

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule    ^$ app/webroot/    [L]
    RewriteRule    (.*) app/webroot/$1 [L]
    </IfModule>
    
  6. 在我的app 目录中检查了.htaccess

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule    ^$    webroot/    [L]
    RewriteRule    (.*) webroot/$1    [L]
    </IfModule>
    
  7. 在我的app/webroot 目录中检查了.htaccess

    <IfModule mod_rewrite.c>
    RewriteEngine On 
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
    </IfModule>
    
  8. 检查 echo phpinfo(); 的输出是否存在 mod_rewrite

  9. /Applications/MAMP/conf/apache/httpd.conf 中替换了所有AllowOverride None 更改为AllowOverride All 用于&lt;Directory&gt; 指令

  10. 注释掉 echo $this-&gt;Html-&gt;css(array('cake.generic.css')); 以防碍事

调试工具栏仍然是这样的:

【问题讨论】:

  • 不编辑 .htaccess 文件怎么样?让他们与 cakephp 默认保持一致。
  • 刚刚将它们全部恢复为默认值,看起来我在尝试解决问题时添加了一些东西。但恐怕还是不一样的结果,谢谢你的建议!

标签: php .htaccess cakephp mod-rewrite mamp


【解决方案1】:

找到了!在某处,我认为在Config/core.php 中取消注释此行是个好主意:

Configure::write('App.baseUrl', env('SCRIPT_NAME'));

但这适用于未启用 url 重写的情况,因此将评论放回原处就可以了!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-04-14
    • 1970-01-01
    • 1970-01-01
    • 2017-06-12
    • 2012-11-22
    • 2010-10-31
    • 2012-12-19
    相关资源
    最近更新 更多