Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why use 404.html instead of index.html #7

Closed
DIYgod opened this issue Nov 28, 2016 · 15 comments
Closed

Why use 404.html instead of index.html #7

DIYgod opened this issue Nov 28, 2016 · 15 comments

Comments

@DIYgod
Copy link

DIYgod commented Nov 28, 2016

I try rename 404.html to index.html, it works well, see: http://dplayer.js.org/docs/

Using 404 has two defect:

  • Can't put docs to second-level directory
  • Not SEO friendly
@QingWei-Li
Copy link
Member

QingWei-Li commented Nov 28, 2016

Of course, It's works. If it is a multi level directory, it will not work. Such as /first/second, the first/second.html is not exist.

If the server can't find the file, it will fallback to 404.html

@DIYgod
Copy link
Author

DIYgod commented Nov 28, 2016

So, why not use index.html....

@QingWei-Li
Copy link
Member

GitHub Pages not support history api fallback. But the url can not be found, the 404.html will be rendered. This first/second.html actually does not exist, but it can be rendered dynamically if it fallback to 404.html. Sorry for my bad english. 😅

@DIYgod
Copy link
Author

DIYgod commented Nov 28, 2016

还是用中文吧...

我知道用 404.html 是可行的,但为什么不用 index.html,想问下这样做的原因是什么?

比如我有个项目DPlayer,dplayer.js.org 一级目录用来做demo页了,然后想在 dplayer.js.org/docs 二级目录做文档页面,如果是 404.html 就无法实现了,只改成 index.html

@MCBBC
Copy link

MCBBC commented Nov 28, 2016

HI ! Man DIYgod is FuTa

@QingWei-Li
Copy link
Member

QingWei-Li commented Nov 28, 2016

index.html 可行,如果你只有一个文档的话。但是多个文档文件就没办法了,比如说我有这样的结构

-| README.md
-| zh-cn.md

其中 README.md 是主页面,我可以直接通过 domain.com 访问。但是要访问 domain.com/zh-cn 就会找不到文件,因为并不存在一个叫 zh-cn.html 的文件,所以就会 fallback 到 404.html。我只是利用了可自定义 404 的特性实现了 "SPA" 的效果

@DIYgod
Copy link
Author

DIYgod commented Nov 28, 2016

奇巧淫技,学到了!

@DIYgod DIYgod closed this as completed Nov 28, 2016
@QingWei-Li
Copy link
Member

至于你说的 SEO,因为内容是动态生成的,似乎没办法做到 😅

@DIYgod
Copy link
Author

DIYgod commented Nov 28, 2016

只是感觉一直返回的是404不太友好... 但这样的好处也很明显...

@QingWei-Li
Copy link
Member

好的 我会在文档里提一下,如果只是单页文档就直接用 index.html

@liulex liulex mentioned this issue Dec 1, 2016
@egoist
Copy link

egoist commented Dec 2, 2016

Since it's always SEO-unfriendly, I think hash routing is fine for both cases (multi-pages and using index.html), maybe add an option for using hash routing?

@haltcase
Copy link

I don't really understand what kind of workflow is supposed to come out of this. If I call my file 404.html, GitHub uses README.md as the index. If I call it index.html, docsify serve docs fails saying there's no 404.html - so I can't even use the dev server. Am I not understanding something here?

@QingWei-Li
Copy link
Member

@citycide docsify-cli bug, fixed in 1.1.0, please upgrade docsify-cli. 😁

@egoist
Copy link

egoist commented Dec 18, 2016

@citycide by the way, you can use .nojekyll to prevent from serving README.md as index

@haltcase
Copy link

@QingWei-Li nicely done, I'm glad I wasn't doing anything glaringly wrong! @egoist thanks for that tip also.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants