【问题标题】:Redirection to 404 pages with .htaccess使用 .htaccess 重定向到 404 页
【发布时间】:2013-05-17 06:36:51
【问题描述】:

我在本地主机中创建了一个名为“example”的文件夹。我在该文件夹中添加了 4 个文件。

  • index.php
  • about.php
  • .htaccess
  • 404.php

当我输入 url http://www.localhost/example/123(工作正常)时,它将进入 404 错误页面。

当我输入 url http://www.localhost/example/index.php/123 时,它不会重定向到 404 页面。 同样发生在示例文件夹中的 about.php 和其他 php 扩展文件。

在我的 htaccess 文件中,我重新定向了不存在的文件 ro 404 页面。但 index.php、about.php.. 以及示例文件夹中所有扩展名为 php 的文件都没有发生。

以下是我当前的 .htaccess 文件。

RewriteEngine On

RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

ErrorDocument 404 /404.php

【问题讨论】:

  • 我了解到您对当前的 .htaccess 文件不满意。你能在你的问题中给出它,以便我们解决它吗?
  • @dystroy...以下是我的 htaccess 文件... RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d ErrorDocument 404 /404.php跨度>
  • @dystroy..我已在问题中添加了我的 htaccess 文件。请查看它并让我知道您的回复。

标签: .htaccess redirect http-status-code-404


【解决方案1】:

如果您想明确禁用路径信息,则必须使用AcceptPathInfo directive

AcceptPathInfo Off

【讨论】:

  • @Ignacio..非常感谢您的回复..现在效果很好..感谢您抽出宝贵的时间阅读我的问题和回复..
  • 如果我在 htaccess 中使用 AcceptPathInfo Off 有什么问题
  • ...如果我在 htaccess 中使用 AcceptPathInfo Off 会有什么影响
  • 是的。您将无法在任何脚本中使用路径信息。
  • ..seo有什么问题吗?
猜你喜欢
  • 2011-12-05
  • 1970-01-01
  • 2023-03-10
  • 1970-01-01
  • 1970-01-01
  • 2019-03-03
  • 2016-11-21
  • 2016-06-05
  • 1970-01-01
相关资源
最近更新 更多