清爽页面提供&QUOT

清爽页面提供&QUOT

本文介绍了清爽页面提供"找不到网页"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有它使用一个单一的NG-视图和多个控制器和视图的应用程序。
如果我通过根,例如导航:www.domain.com,一切正常。但如果我按Ctrl + R(刷新),那么它给了我404 eror找不到网页。例如:刷新此页面上给我的错误。

I have an app where it uses a single ng-view and multiple controllers and views.If I navigate through the root, eg: www.domain.com, everything works. Except that if I hit Ctrl+R (Refresh) then it gives me the 404 eror Page not Found. eg: refreshing on this page gives me error.http://domain.com/item/1/.

但是,如果我使用hashbang然后访问该页面它works.eg:

But if I access the page using the hashbang then it works.eg: http://domain.com/#!/item/1/

我该如何解决这个问题?
我htacess是空的。并采用镀铬即时通讯支持HTML5 hashbang。

How shall I fix this problem?My htacess is empty. And Im using chrome which support html5 hashbang.

推荐答案

在浏览器调用 http://domain.com/#!/item/1/ ,它调用 http://domain.com/ 的索引页,你的JS然后确定哪些内容通过分析这个标签显示。

When the browser calls http://domain.com/#!/item/1/, it is calling the index page of http://domain.com/, your JS then determines what content to display by analysing the hashtag.

在浏览器调用 http://domain.com/1/ ,您的服务器尝试以服务 HTTP索引页:/ /domain.com/1 / ,它无法找到,因此抛出一个404错误。

When the browser calls http://domain.com/1/, your server is attempting to serve the index page of http://domain.com/1/, which it cannot find and therefore throws a 404 error.

要实现你想要什么,你要么需要:

To achieve what you want, you'll either need to:


  • 创建一个重写规则重写链接到您的根索引页面

  • 调整JS所以它生成的#标签,而不是URL。如果你正在使用AngularJS然后关闭HTML5模式 $ locationProvider.html5Mode(假);

  • 把一个索引页 http://domain.com/1/ 重定向到 http://domain.com/#! /项目/ 1 / - 但是请注意,这将需要重复每/ prettyPath /你克里特岛

  • Create a rewrite rule to rewrite the links to your root index page
  • adjust your JS so that it generates the hashtag instead of the URL. If you are using AngularJS then turn off html5 mode with $locationProvider.html5Mode(false);, or
  • put an index page in http://domain.com/1/ that redirects to http://domain.com/#!/item/1/ - however note that this would need to be repeated for every /prettyPath/ you crete.

假设你使用的是Apache和你的索引文件的index.php,尝试添加下面为您.htaccess文件尝试其他两种解决方案的任何之前创建一个重写规则。

Assuming you are using Apache and your index file is index.php, try adding the following to your .htaccess file to create a rewrite rule before trying either of the other two solutions.

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)       /index.php/#/$1
</IfModule>

如果您使用的是纯AngularJS / Ajax解决方案没有服务器端逻辑,改变index.php来的index.html(或index.htm取决于你的根索引文件名)。

If you are using a pure AngularJS/Ajax solution without a server side logic, change index.php to index.html (or index.htm depending on your root index filename).

这篇关于清爽页面提供&QUOT;找不到网页&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 06:16