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

为了防止在目录页刷新会提示404,Nginx和Apache都需要设置Rewrite #10

Open
IptablesNat opened this issue Aug 21, 2019 · 5 comments

Comments

@IptablesNat
Copy link

IptablesNat commented Aug 21, 2019

Nginx 的 Rewrite 配置

location / {
  if (!-e $request_filename){
    rewrite ^(.*)$ /index.html break;
  }
}

Apache 的 Rewrite 配置

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

作者在 deploy.md 未给出 ngnix 的 rewrite 信息。

@IptablesNat IptablesNat changed the title 为了防止目录页刷新会提示404,Nginx和Apache都需要设置Rewrite 为了防止在目录页刷新会提示404,Nginx和Apache都需要设置Rewrite Aug 21, 2019
@ganlvtech
Copy link
Owner

你的意思是在出现 404 时直接返回首页吗?

这个可能与项目无关,你可以自行设置 404 页面,例如 error_page 指令。

error_page 404 /error/404.html;

或者直接使用首页作为 404 页面

error_page 404 =200 /index.html;

参考 https://stackoverflow.com/questions/19487365/how-do-i-force-redirect-all-404s-or-every-page-whether-invalid-or-not-to-the/19489441#19489441

可以提供一下您的复现过程吗?

@IptablesNat
Copy link
Author

sorry,重点在最后一句
”作者在 deploy.md 未给出 ngnix 的 rewrite 信息。“
我只是把你给的apache rewrite信息转换了一下,贴上来了而已。

404意思是指,如果没有正确配置rewrite,,在目录页刷新会提示404
所以我把apache和ngnix的rewrite配置都贴了出来。。。

@ganlvtech
Copy link
Owner

可以提供一下您的复现过程吗?我自己测试没有问题,刷新不会 404。

@IptablesNat
Copy link
Author

额,我说的是没配置好rewrite会有404,你的配置好了当然不会404,,,,
你把rewrite去掉就有404。。。。

@ganlvtech
Copy link
Owner

@IptablesNat 我是按照我目前文档中配置的,没有使用 rewrite,也没有出现问题,没有 404 的问题。

server {
        listen 80;
        root /srv/www/down_52pojie_cn;
        index /index.html;
        server_name down.ganlvtech.cn;
}

请提供出错时的完整的 nginx 配置文件,帮助我分析问题原因。

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

2 participants