【发布时间】:2015-03-18 07:55:43
【问题描述】:
我的新 Ember-CLI 应用程序使用 URL 中的用户门户 slug 向用户显示正确的信息。例如(假网址):http://my.server.portals.com/robertplant
我正在使用路由器和适配器逻辑的组合从 url slug 获取用户门户名称,然后显示与之相关的数据。它可能需要更多的工作,但这是我目前所做的:
路由器代码提取:
Router.map(function () {
this.route('portal', {path: '/:portal_slug'}, function () {
this.resource('account', {path: '/'});
});
});
适配器代码提取(用于基于门户访问正确的 API 端点):
namespace: function () {
var portal = window.location.pathname.match(/^\/([^\/]*).*$/)[0];
return 'abc' + portal + '/api/v1';
}.property().volatile(),
我可以毫无问题地在本地访问应用程序(例如:http://localhost:4200/robertplant/)。它使用 Ember-CLI 的内置 Web 服务器运行。
但是,当我将应用程序移动到运行 Apache 的服务器并尝试访问它时(例如:http://my.server.portals.com/robertplant),我得到:
Not Found
The requested URL /robertplant was not found on this server.
我想这是有道理的,因为实际上并没有一个与 slug 同名的目录。但是,我认为必须有一种方法可以告诉 Apache 忽略它认为存在的问题,并允许应用路由器处理它。本地网络服务器正在以某种方式做到这一点。
理想情况下,该解决方案会保持 URL 显示不变。此外,重写请求以指向 http://my.server.portals.com?slug=robertplant 之类的内容会导致在错误路径中查找 Ember-CLI 资产(无法动态设置 baseUrl)。
对于如何在 Apache 中设置应用程序以实现这一点的任何反馈,我将不胜感激。
【问题讨论】:
-
我看到您在本地机器的 4200 端口上加载应用程序,除非您手动更改它,否则绝对不是 Apache 端口。当您加载 my.server.portals.com/robertplant 时,它正在寻找 DocRoot 中的文件夹 robertplant,它显然不存在并且遇到 404。如果您希望 Apache 从在另一个端口上运行的应用程序获取页面,我猜最好使用“代理通行证”。
-
我猜你还需要修改.htaccess文件。