0

我希望让我的 Cake 应用程序中的某些 url 成为基于子域的。

因此,例如使:domain.com/posts/index.json成为api.domain.com/posts

我试过了:

$subdomain = substr(env("HTTP_HOST"), 0, strpos(env("HTTP_HOST"), ".")); 

if ($subdomain == 'api') {
    Router::connect('/', array('controller' => 'posts', 'action' => 'index')); 
}

但它只是带来了一个 404。注意我已经关闭了通配符子域,因此随机子域仍然不会加载主站点(是否可以允许某些子域?例如,允许 api.domain.com 但出错在 fake.domain.com 上)

另外,如何将 JSON 扩展作为路由器阵列的一部分进行处理?

4

2 回答 2

0

从 2.x 开始,Cake 没有任何东西支持子域。已经对此进行了讨论/工作,但不确定何时可用。

直到它是你将需要忍受普通的网址或大量的黑客攻击。

于 2013-01-11T17:27:25.360 回答
0

您可以在您的 routes.php 中使用下面的代码同时确保您已经可以访问子域。

$subdomain = substr( env("HTTP_HOST"), 0, strpos(env("HTTP_HOST"), ".") );
if( strlen($subdomain) > 0 && $subdomain == "api" ) {
    Router::connect('/:action/*', array('controller' => 'posts'));
}
于 2013-07-01T12:33:24.753 回答