【问题标题】:ErrorDocument 404 print file nameErrorDocument 404 打印文件名
【发布时间】:2013-11-07 23:59:45
【问题描述】:

我有一个文件index.php,并在同一级别有一个.htaccess,代码如下:

ErrorDocument 404 index.php

当我生成一个未找到的错误时,会打印一个带有文件名的页面,因此,在这种情况下,我只看到 index.php 作为文字文本。我想要的显然是重定向到主页。

对这个问题有任何想法吗?

www\site 
  -index.php
  -.htaccess 

【问题讨论】:

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


    【解决方案1】:

    你想要:

    ErrorDocument 404 /index.php
    

    ErrorDocument docs

    对于本地网络路径(相对于 DocumentRoot),URL 可以以斜杠 (/) 开头,或者是客户端可以解析的完整 URL。或者,可以提供消息以由浏览器显示。例子:

    ErrorDocument 500 http://foo.example.com/cgi-bin/tester
    ErrorDocument 404 /cgi-bin/bad_urls.pl
    ErrorDocument 401 /subscription_info.html
    ErrorDocument 403 "Sorry can't allow you access today" 
    

    因此,如果它不是 FQDN 或以 / 开头的内容,则假定您希望显示自定义消息。

    【讨论】:

    • 如果ErrorDocument 404 /index.php 对您不起作用,则意味着 index.php 不在您的目录根目录中 - 目录根目录通常是您在登录 FTP 后看到的位置 :) 很常见的是 @ 987654326@ 或 ErrorDocument 404 /domain/www/index.php 或只是 ErrorDocument 404 /domain/index.php - 这可能不是每个人都清楚:)
    • 如果我将您的目录结构和我的评论结合起来,我会得到:ErrorDocument 404 /www/site/index.php 希望我能帮上忙。 :)
    猜你喜欢
    • 2013-01-04
    • 2011-05-05
    • 2018-01-03
    • 2014-05-23
    • 1970-01-01
    • 2012-08-25
    • 2012-12-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多