htaccess错误404处理不起作用+动态404错误页面? [英] htaccess error 404 handling not working + dynamic 404 error page?

查看:206
本文介绍了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错误页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆