【发布时间】:2014-08-12 13:54:29
【问题描述】:
我的 CakePHP 站点位于 http://localhost/somepath/。我应该如何设置 CakePHP 以便一切正常?
我尝试添加添加行
RewriteBase /somepath/
到.htaccess 和app/webroot/.htaccess。没有其他方法可以使 URL 重写工作(否则,我在访问该站点时总是得到 404)。此解决方案有效,但从 CLI 使用时会中断路由。例如,当我使用
Router::url(array('controller' => 'posts', 'action' => 'view', 3), true);
在 Shell 中,我得到 http://localhost/posts/view/3 而不是 http://localhost/somepath/posts/view/3。
所以除了更改.htaccess之外,我还尝试在core.php中设置App.fullBaseUrl,如下所示:
Configure::write('App.fullBaseUrl', 'http://localhost/somepath');
这样,我在 Shells 中获得了正确的 URL,但在网页上却没有——例如使用与上面相同的Router::url 调用,我得到http://localhost/somepath/somepath/posts/view/3。
【问题讨论】:
-
谢谢@Dave,但是由于我从 Apache 而不是从带有 unchanged
.htaccess的 Cake 收到错误 (404),我想有一个问题URL 重写,而不是 Cake 配置。 -
是的。正如我所说,如果我设置
RewriteBase,它就可以工作。
标签: php url cakephp mod-rewrite cakephp-2.5