1

我的 CakePHP 站点位于http://localhost/somepath/. 我应该如何设置 CakePHP 以便一切正常?

我尝试添加添加行

RewriteBase  /somepath/

.htaccessapp/webroot/.htaccess。没有其他方法可以使 URL 重写工作(否则,访问该站点时我总是得到 404)。此解决方案有效,但从 CLI 使用时会中断路由。例如,当我使用

Router::url(array('controller' => 'posts', 'action' => 'view', 3), true);

在壳牌中,我得到http://localhost/posts/view/3而不是http://localhost/somepath/posts/view/3.

所以除了更改之外.htaccess,我还尝试了设置App.fullBaseUrlcore.php如下所示:

Configure::write('App.fullBaseUrl', 'http://localhost/somepath');

这样,我在 Shells 中获得了正确的 URL,但在网页上却没有——例如,使用与Router::url上面相同的调用,我得到http://localhost/somepath/somepath/posts/view/3.

4

1 回答 1

3

应该/somepath/在 url 中可见还是您尝试在 url 中隐藏此子文件夹?

您是否尝试添加RewriteBase /somepath/所有 3 个 htaccess 文件?

/yourcakedir/.htaccess
/yourcakedir/app/.htaccess
/yourcakedir/app/webroot/.htaccess

然后在

/yourcakedir/app/config/bootstrap.php

添加

Configure::write('App.base','');

您还可以添加

Configure::write('App.base','/');

但这在某些情况下会出现双斜杠,因为您的 htaccess RewriteBase 已经以斜杠结尾。

如果你设置App.base你不应该在你的core.php

Configure::write('App.fullBaseUrl', 'http://localhost/somepath');
于 2014-09-01T19:20:24.180 回答