【问题标题】:nginx rewrite to remove /index.html and keep query string and hashnginx 重写以删除 /index.html 并保留查询字符串和哈希
【发布时间】:2017-05-23 04:49:30
【问题描述】:

我的 nginx 配置将 index index.html 设置为其索引页。

当它作为渐进式 Web 应用程序(使用 Angular)打开时,由于某种原因,它会加载 /index.html#/route 而不是 /#/route

我想:

  1. 检测URL是否包含/index.html',以及
  2. 重写以删除 /index.html 以更正 URL。

这可以在 nginx 中实现,还是我应该在 javascript 中实现?

我在这里找到了articles 和答案,但它们似乎没有考虑到对保留很重要的哈希标签和查询字符串参数。

【问题讨论】:

    标签: javascript angularjs .htaccess nginx


    【解决方案1】:

    您需要更好的正则表达式模式(基于文章)。

    rewrite ^(?:.*\/)index.html(.*) /$1 permanent;
    

    它在 .html 之后捕获 URL,第一组是未捕获的。

    换人:

    /index.html#/route    /#/route
    /index.html#something    /#something
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-09
      • 1970-01-01
      • 2012-01-15
      • 1970-01-01
      • 2012-09-25
      • 1970-01-01
      相关资源
      最近更新 更多