【问题标题】:404 Redirect is not working404重定向不起作用
【发布时间】:2011-03-13 10:27:04
【问题描述】:

在我的 htaccess 文件中,我的 ErrorDocument 404 语句没有重定向到 index.php。相反,我收到了一个常规的 404 错误。这是一个常规的 apache 安装。

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    #Removes access to the system folder by users.
    #Additionally this will allow you to create a System.php controller,
    #previously this would not have been possible.
    #'system' can be replaced if you have renamed your system folder.
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    #Checks to see if the user is attempting to access a valid file,
    #such as an image or css document, if this isn't true it sends the
    #request to index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.
    # Submitted by: ElliotHaughin

    ErrorDocument 404 /index.php
</IfModule>

【问题讨论】:

  • 可怜的你!我真的希望你能解决这个问题
  • 你用哪个浏览器来测试这个?
  • 你知道你是否开启了mod_rewrite(你可以通过echo phpinfo()查看)?另外,“常规404”是什么意思。你是说 Apache 的 404 还是 CI 的?
  • 尝试使用其他浏览器。如果某些浏览器获得某些状态代码(例如,404 而不是 200),则某些浏览器不会显示响应的内容。另外,mod_rewrite 是否启用?

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


【解决方案1】:

在此处需要更多信息。正在获取 CodeIgniter 的 404 还是 Apache 的 404?

如果您收到 CodeIgniter 的 404,它按预期工作。

【讨论】:

  • 您正在重定向到 /index.php,但那是 index.php 所在的位置吗?在文档根目录中?还是您在子文件夹中工作?
【解决方案2】:

我整理好了。我在 Code Igniter 中使用了一个自定义错误处理路由器,并跳过了 .htaccess 文件。我没有直接访问客户端服务器的权限,所以我自己进行了更改,并为他们提供了一个用于 CI 的标准 .htaccess 文件。走这条路只是让我的生活变得更简单。

【讨论】:

    猜你喜欢
    • 2013-01-30
    • 1970-01-01
    • 1970-01-01
    • 2018-02-18
    • 2011-12-01
    • 1970-01-01
    • 2014-04-20
    • 1970-01-01
    • 2015-09-25
    相关资源
    最近更新 更多