我的 CakePHP 站点位于http://localhost/somepath/
. 我应该如何设置 CakePHP 以便一切正常?
我尝试添加添加行
RewriteBase /somepath/
到.htaccess
和app/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.fullBaseUrl
,core.php
如下所示:
Configure::write('App.fullBaseUrl', 'http://localhost/somepath');
这样,我在 Shells 中获得了正确的 URL,但在网页上却没有——例如,使用与Router::url
上面相同的调用,我得到http://localhost/somepath/somepath/posts/view/3
.