【问题标题】:htaccess return 404 instead of 200htaccess 返回 404 而不是 200
【发布时间】:2018-06-28 02:23:20
【问题描述】:

我在我的 htaccess 文件中使用这一行来返回 index.html 在任何 404 的情况下:

错误文档 404 /index.html

可以,但文件在浏览器中返回 404 代码。

如何在我的 htaccess 中更改此行以使用 index.html 文件返回 200 代码?

【问题讨论】:

    标签: .htaccess


    【解决方案1】:

    ErrorDocument 告诉您的 httpd 与 404 错误代码一起发送哪个文档。如果您想始终发送index.html 文件,可以使用mod_rewrite

    这是一个例子:

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /index.html
    

    这会(在内部)将所有未映射到文件或目录的请求重写到您的 index.html 页面。

    【讨论】:

      【解决方案2】:

      您可以使用FallbackResource 代替ErrorDocument 404 /index.html 指令:

      FallbackResource /index.php
      

      按照关于FallbackResource的手册:

      使用它为任何不映射到文件系统中任何内容的 URL 设置处理程序,否则将返回 HTTP 404(未找到)。

      【讨论】:

        猜你喜欢
        • 2017-10-26
        • 1970-01-01
        • 1970-01-01
        • 2018-12-05
        • 2013-04-08
        • 1970-01-01
        • 2010-09-25
        • 2016-02-10
        • 2019-10-29
        相关资源
        最近更新 更多