【问题标题】:Show 404 custom page without redirecting to it显示 404 自定义页面而不重定向到它
【发布时间】:2018-01-05 13:25:42
【问题描述】:

我想显示我的 404 自定义页面而不重定向到它(以便用户看到他在导航栏中写的内容,而不是看到 https://abadroch.fr/docs/404/)。我的研究让我遇到了与 PHP 相关的问题,但我只是使用了 local-error-pages.conf(错了吗?),它与 .htaccess 非常相似

# Customizable error responses come in three flavors:
# 1) plain text
# 2) local redirects
# 3) external redirects
#
# Some examples:
#ErrorDocument 500 "The server made a boo boo."
#ErrorDocument 404 /missing.html
#ErrorDocument 404 "/cgi-bin/missing_handler.pl"
#ErrorDocument 402 http://www.example.com/subscription_info.html
#
ErrorDocument 404 https://abadroch.fr/docs/404/index.html

(我使用了 URL,因为路径不起作用)

However I've tested a thing concerning php (doesn't work of course)
# Customizable error responses come in three flavors:
# 1) plain text
# 2) local redirects
# 3) external redirects
#
# Some examples:
#ErrorDocument 500 "The server made a boo boo."
#ErrorDocument 404 /missing.html
#ErrorDocument 404 "/cgi-bin/missing_handler.pl"
#ErrorDocument 402 http://www.example.com/subscription_info.html
#
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /var/wwww/docs/404/index.html [L]

(在编辑之前,已经有一些RewriteCond/RewriteRule,所以不需要打开RewriteEngine)

感谢您的帮助! (对不起我的英语不好,我是 16 岁的法国人)

【问题讨论】:

    标签: apache http-status-code-404


    【解决方案1】:

    解决了。

    我必须将我的 404 html 文件移动到路径 /var/www(重要)并添加到文件 /etc/apache2/sites-available/default.conf

    Redirect 404 /404.html
    

    我还更改了localized-error-pages.conf:

    ErrorDocument 404 /404.html
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-09-14
      • 1970-01-01
      • 2012-10-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-23
      • 2015-08-01
      • 2013-03-26
      相关资源
      最近更新 更多