首页 文章

显示404自定义页面而不重定向到它

提问于
浏览
0

我想显示我的404自定义页面而不重定向到它(以便用户看到他在导航器栏中写的内容而不是看到https://abadroch.fr/docs/404/) . 我的研究让我遇到了与PHP有关的问题,但我只是使用了localized-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)

谢谢你的帮助 ! (抱歉我的英语不好我是16yo法国人)

1 回答

  • 0

    解决了 .

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

    Redirect 404 /404.html
    

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

    ErrorDocument 404 /404.html
    

相关问题