【问题标题】:handle error pages using PHP and htaccess使用 PHP 和 htaccess 处理错误页面
【发布时间】:2013-05-21 04:52:23
【问题描述】:

我想在我的 htaccess 文件中添加如下代码:

ErrorDocument 403 /error/403
ErrorDocument 404 /error/404
ErrorDocument 500 /error/500
...

并有一个 PHP 文件使用 GET (file.php?a=404) 为我处理错误页面。

现在,我只需要一个 htaccess 代码来为我将“/error/404”重写为“file.php?a=404”。我该怎么办?!

【问题讨论】:

    标签: php .htaccess error-handling


    【解决方案1】:

    您可能希望自定义其他几个错误文档。 400 - 错误请求 401 - 需要授权 403 - 禁止目录 404页面不存在 500 - 内部服务器错误

    对于您要使用的每一个,只需在您的 .htaccess 文件中添加一行并创建相应的页面。

    ErrorDocument 400 /errors/badrequest.html
    ErrorDocument 401 /errors/authreqd.html
    ErrorDocument 403 /errors/forbid.html
    ErrorDocument 404 /errors/notfound.html
    ErrorDocument 500 /errors/serverr.html
    

    【讨论】:

      【解决方案2】:
      ErrorDocument 404 /path/to/file.php?a=404
      

      【讨论】:

        【解决方案3】:
        ErrorDocument 404 /path/to/yourfile.php
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2013-09-19
          • 2012-11-23
          • 1970-01-01
          • 2011-11-21
          • 2012-01-27
          • 1970-01-01
          相关资源
          最近更新 更多