【问题标题】:html5mode angularjs ui-router .htaccess re write ruleshtml5mode angularjs ui-router .htaccess 重写规则
【发布时间】:2016-06-27 04:17:54
【问题描述】:

我知道这个问题已经在堆栈溢出中被问过很多次了,但我无法得到正确的结果。

我试过这个链接:htaccess redirect for Angular routes

https://github.com/angular-ui/ui-router/wiki/Frequently-Asked-Questions#how-to-configure-your-server-to-work-with-html5mode

所以基本上,我在我的应用中使用https://github.com/angular-ui/ui-router 进行导航,

我们有一个这样的网址:

  1. www.xyz.com/products 工作正常,(硬刷新时工作正常)

  2. www.xyz.com/displayOrders/12 为什么?

我的嵌套视图也不起作用:

  1. www.xyz.com/message/notfication/12

我在 .htaccess 文件中写的是:

<IfModule mod_rewrite.c>
    Options +FollowSymlinks
    RewriteEngine On
    # Don't rewrite files or directories
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]


  RewriteRule (.*) index.html [L]


</IfModule>

我的基本标签是这样的:

<base href="/"> and i also made html5mode as true in app.js

【问题讨论】:

    标签: php angularjs regex apache mod-rewrite


    【解决方案1】:

    你应该这样写.htaccess

    <IfModule mod_rewrite.c>
    Options +FollowSymlinks
    RewriteEngine On
    # Don't rewrite files or directories
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]
    
    RewriteRule (.*) /index.html [L]
    </IfModule>
    

    如果您的项目在子目录示例:www.xyz.com/shop/ 您应该像这样编写最后一个重写器

    RewriteRule (.*) /shop/index.html [L]
    

    和这样的基本标签

    <base href="/shop/">
    

    【讨论】:

      猜你喜欢
      • 2014-12-21
      • 2016-05-03
      • 1970-01-01
      • 2011-11-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多