【问题标题】:Angularjs Routeprovider in MODx subfolderMODx 子文件夹中的 Angularjs Routeprovider
【发布时间】:2017-04-22 20:42:03
【问题描述】:

我在 MODx 网站上运行了 angularjs 应用程序。有一些页面的 URL 像

localhost/www.mysite.com/angularapp/

其中包含应用程序。

应用内的 URL 看起来像

localhost/www.mysite.com/angularapp/category/1

base href 设置为 /www.mysite.com/angularapp/

一切正常,但我无法直接访问应用程序的子页面。

如果我在地址栏中输入 localhost/www.mysite.com/angularapp/category/1,我会进入 modx 起始页。但是,如果我通过应用程序访问链接 - 它可以工作。

我错过了什么?

谢谢

【问题讨论】:

    标签: angularjs modx ngroute route-provider angularjs-ng-route


    【解决方案1】:

    您必须从默认的 htaccess 友好 URL 重写中排除 angularapp 文件夹,并为此添加新规则。包括以下行

    RewriteRule ^(angularapp/)(.*)$ index.php?q=$1&r=$2 [L,QSA]
    

    在友好 URL 部分之前。然后,角度应用程序必须与 $_GET['r'] 一起使用。

    # The Friendly URLs part
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
    

    编辑:将 htaccess 代码更改为最终解决方案。

    【讨论】:

    • 听起来不错。但是角度应用程序是在 modx 模板中定义的...... /angularapp/ 是 modx 资源之一。如果我排除它,我会得到 404...
    • 如果一切都发生在 MODX 中(路由 angularapp/ 运行应用程序代码的唯一资源),您有多种选择。可以在友好 URL 部分之前构建自己的重写规则: RewriteRule ^(angularapp/)(.*)$ index.php?q=$1&r=$2 [L,QSA] 角度应用程序必须与 $_GET[ 'r'] 那么。另一个可能是 customRequest extra,它可以自己路由到应用程序的多个请求参数。
    • 我认为 RewriteRule ^angularapp/. /www.mysite.com/angularapp/$1 [L] 做到了)你的重写也有效。会坚持下去,因为它更通用
    • 你的规则没有意义。它会重写以 angularapp/ 开头的 url,加上一个指向您的域的符号加上 angularapp/ 之后没有路径($1 永远不会填充)。
    猜你喜欢
    • 2012-07-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-12
    • 1970-01-01
    相关资源
    最近更新 更多