htaccess错误404处理不起作用+动态404错误页面?

编程入门 行业动态 更新时间:2024-10-24 02:36:20
本文介绍了htaccess错误404处理不起作用+动态404错误页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

首先,我的ErrorDocument 404 / v1从未重定向,但是如果我在Chrome浏览器检查器中查看,我确实有404错误。起初我以为是因为我确实需要指定一个文件,例如:error.html,但这也不起作用。 / v1只是一个wordpress子域,我想在那里重定向所有错误。 / v1放在子域的主页上。

First of all, my ErrorDocument 404 /v1 is never redirecting, but if I look in the Chrome Inspector, I really have a 404 error. At first I thought it was because I really needed to specify a file ex: error.html, but that didn't work either. /v1 is just a wordpress subdomain, and I want to redirect all of my errors there. /v1 falls on my homepage of my subdomain.

我也想使错误页面动态化,但是我不知道该怎么做。像这样的东西:

Also I would like to make the error page dynamic, but I can't figure how to do that. Something like that:

RewriteCond %{REQUEST_FILENAME} public_html/(.*) ErrorDocument 404 /v1/%1

有什么想法吗?谢谢!!!

Any ideas? Thank you!!

推荐答案

您需要通过php脚本返回404:

You're goinmg to need to return the 404 through a php script:

RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /404.php?path=$1 [L]

在 404中。 php文件:

<?php header("HTTP/1.0 404 Not Found"); print('The file that you requested: ' . $_GET['path'] . ' was not found\n'); // or include a special 404 page include ('/path/to/' . $_GET['path']); ?>

否则您可能会丢失?path = $ 1 部分,只需查看 $ _ SERVER ['REQUEST_URI'] 。

Or you could lose the ?path=$1 part completely and just look in $_SERVER['REQUEST_URI'].

更多推荐

htaccess错误404处理不起作用+动态404错误页面?

本文发布于:2023-10-31 15:40:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1546533.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误   不起作用   页面   动态   htaccess

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!