【问题标题】:ErrorDocument doesn't seem to be working in my .htaccessErrorDocument 似乎在我的 .htaccess 中不起作用
【发布时间】:2010-09-09 11:09:00
【问题描述】:

谁能给点建议?我希望我网站的访问者的默认页面是 index.php,对于所有不存在的页面,访问者应该看到 errordoc.php

所以我把它放在 .htaccess 中:

ErrorDocument 404 /errordoc.php

Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^mysite\.org\.uk$ [NC]
RewriteRule ^(.*)$ http://mysite.org.uk/$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

不幸的是,所有内容都会写入 index.php,包括错误。我试过问我的朋友 Google,但他今天休息!

【问题讨论】:

  • 奇怪,看起来不错。去掉rewrite部分还能用吗?
  • 谢谢 Pekka,我已经删除了最后一个重写规则,现在它工作得很好。
  • 其他一切都留在原地了吗?哈哈

标签: php apache .htaccess errordocument


【解决方案1】:

您的最后一条规则将捕获所有无法映射到现有文件 (RewriteCond %{REQUEST_FILENAME} !-f) 或现有目录 (RewriteCond %{REQUEST_FILENAME} !-d) 的请求。这就是不提供错误文档的原因。

【讨论】:

    【解决方案2】:

    您在此文件中有 2 个不兼容的部分。选择一个
    仅保留第一行或仅保留文件的其余部分。但不是两者兼而有之。

    下面三行告诉 web-server 将所有不存在的页面指向 index.php,而不是 errordoc.php

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-11-27
      • 2011-12-01
      • 2020-05-02
      • 2011-01-15
      • 1970-01-01
      • 2018-01-03
      • 2014-05-23
      • 2011-08-18
      相关资源
      最近更新 更多