【问题标题】:Emberjs application refresh on route other than index gives 404 errorEmberjs 应用程序在索引以外的路由上刷新给出 404 错误
【发布时间】:2014-03-12 03:53:20
【问题描述】:

我有一个使用 Ember-App-Kit(EAK) 提供的入门套件的小型 ember 应用程序。在构建生产后,我已将 dist 目录上传到 AWS EC2 实例。

我现在面临的问题::

  1. 当我点击根 url 时,我可以看到索引页面,而从索引页面中存在的链接转到任何其他路由时,它工作正常,让我可以转到该页面。 当我尝试在该页面本身上点击刷新时会出现问题。

首先我认为这是由于权限错误,但它只是单个 html 文件并且 js 和 css 正确加载。 然后认为可能是 htaccess 问题所以尝试插入一个,但之后也没有效果。 应用程序源代码的条带化版本位于Source Code

.htaccess 用于重定向的文件::

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !index
RewriteRule ^(.*)$ /index.html [L]

【问题讨论】:

  • 我很想看到一个不涉及 nginx 的答案。

标签: javascript apache .htaccess ember.js http-status-code-404


【解决方案1】:

我实际上不知道如何使用 Apache 服务器来执行此操作,所以我安装了 nginx,它使用了我在配置文件中提供的重写规则。

server {
        root /var/www/{Your App Directory Path Here};
        index index.html index.htm;
        server_name {Your website URL or IP address here};

        location / {
                try_files $uri $uri/ /index.html?/$request_uri;
        }
}

您可以在这里找到更多讨论:Ember-App-Kit Git Repo Issue 486

【讨论】:

    【解决方案2】:

    正如this post 中所述,使用FallbackRessource 是完成此任务的最简单方法:

    FallbackResource /index.html
    

    它可以在.htaccess 中使用,但由于每个请求都会解析 .htaccess,我建议将它放在 httpd.conf 或虚拟主机中。

    【讨论】:

      【解决方案3】:

      无论访问什么 URL,您都需要确保您的网络服务器为您的“索引”页面提供服务。

      对于 Apache,您通常会使用重写规则,这里有一些关于为 Ember 设置此规则的讨论 http://discuss.emberjs.com/t/apache-rewrite-rule-for-html5-browser-history-url-bookmarkability/1013

      【讨论】:

      • 你能发布你的 apache 重写规则和一些关于你的主机设置的细节吗?
      • 默认设置。启用虚拟主机。我有一个 .htaccess 文件,它可以重定向让我将其添加到问题中。
      • 如果是默认设置,.htaccess 文件将被忽略,您需要确保在虚拟主机配置中设置了“AllowOverride All”
      • 是的@Kevin 我确实将它设置为全部,除了它是默认值。我也尝试了多种设置,例如将重定向规则放在 conf 文件中,并将 AllowOverride 更改为所有位置的所有位置,然后返回到无,然后将某些位置更改为全部,有些位置设置为无。没有任何效果。
      • @KevinAnsfield 你能看看这个stackoverflow.com/questions/37480357/…
      猜你喜欢
      • 1970-01-01
      • 2018-11-30
      • 2016-12-31
      • 2019-07-08
      • 2020-06-06
      • 1970-01-01
      • 2021-12-26
      • 1970-01-01
      • 2019-07-02
      相关资源
      最近更新 更多