【问题标题】:Can I NOT send a HTTP 404 error on a 404 page?我可以不在 404 页面上发送 HTTP 404 错误吗?
【发布时间】:2015-03-02 13:16:14
【问题描述】:

所以基本上我有我的网站,我正在努力让它与所有东西兼容。

您转到页面:/Page_Name

但是 Page_Name 页面不存在,但是 404 页面是处理请求的。我几乎将它用作 PHP GET 命令。

Web 浏览器可以工作,但其他一些脚本会失败,因为 HTTP 返回 404。

如何在不为每个页面创建文件的情况下解决此问题?我可以使用 .htaccess 文件使“GET”命令在没有“?Name=Page_Name”的情况下工作吗?

【问题讨论】:

  • 您是否想说您希望有一个文件来处理所有请求,而不是为多个页面创建多个文件?
  • @anubhava 是的,请。
  • @GiamPy 差不多,是的。

标签: php .htaccess get http-status-code-404 server


【解决方案1】:

您可以在DOCUMENT_ROOT/.htaccess 文件中将此规则用作catch all 规则

DirectoryIndex index.php
RewriteEngine On
RewriteBase /

# If the request is not for a valid directory
RewriteCond %{REQUEST_FILENAME} !-d
# If the request is not for a valid file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]

然后在index.php 中,您可以使用$_SERVER['REQUEST_URI'] 来检查原始URI 是什么。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-04-08
    • 2013-01-09
    • 2011-05-24
    • 2010-10-24
    • 2011-06-25
    • 1970-01-01
    • 2010-10-13
    • 1970-01-01
    相关资源
    最近更新 更多