htaccess ErrorDocument 404重定向不工作

编程入门 行业动态 更新时间:2024-10-27 10:25:48
本文介绍了htaccess ErrorDocument 404重定向不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 请告诉我为什么这不工作。这是工作,但莫名地决定停止工作。 在php中,如果页面不是这样的话,我发出404。

if(checkPageExists($ escaped_url_page_name) ){ header('HTTP / 1.1:200 OK'); } else { header(HTTP / 1.0 404 Not Found); 死}

我的htaccess是

php_flag magic_quotes_gpc Off RewriteEngine On RewriteCond%{REQUEST_FILENAME}!-f RewriteCond%{REQUEST_FILENAME}!-d RewriteRule ^(。*)$ /index.php?/$1 [L] ErrorDocument 404 /404.php

404页面在根目录下,名称为404.php。为什么五分钟前没有工作,没有任何改变。我已经用fiddler测试了这个页面,它确实是抛出了404的,但重定向没有发生。我实现了友好的URL,但我不会认为这会影响它,因为htaccess中的/是指我想到的网站的物理根。感谢提前。

解决方案

我有一个类似的问题一次 - 当PHP抛出一个404标题时,Apache一般不会404页面。 (编辑:这可能与PHP是否输出任何文本有关,我还没有真正尝试过)。如果您检查浏览器中的标题,您可以看到404标题有效,即使页面为空

我不确定自动化解决方案,但是我刚刚做了一个 http_error($ code)函数打印我的自定义错误页面,并随着 header()一起调用,只要我的代码手动触发了一个404.然后我绑定了一些代码到 ErrorDocument 仅调用 http_error :

ErrorDocument 404 index.php?http_error = 404 ErrorDocument 403 index.php?http_error = 403

...等等。

Please tell me why this is not working. It was working but has inexplicably decided to stop working. In php I issue a 404 if the page is not found like so.

if(checkPageExists($escaped_url_page_name)){ header('HTTP/1.1: 200 OK'); }else{ header("HTTP/1.0 404 Not Found"); die; }

My htaccess is

php_flag magic_quotes_gpc Off RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /index.php?/$1 [L] ErrorDocument 404 /404.php

The 404 page is on the root and is name 404.php. Why would that not work when five minutes ago it was and nothing has changed. I have tested the page with fiddler and it is indeed throwing the 404's but the redirect is not happening. I have friendly urls implemented, but I would not think this affects it as the "/" in the htaccess refers to the physical root of the site I thought. Thanks in advance.

解决方案

I had a similar issue once - when PHP throws a 404 header, Apache generally won't make a 404 page for it. (Edit: It probably has to do with whether PHP outputs any text. I haven't really experimented with it much.) If you check the headers in your browser, you can see that the 404 header worked, even if the page is blank.

I'm not sure about an automated solution, but I just made an http_error($code) function that prints my custom error page and called that along with header() whenever my code manually triggered a 404. Then I bound a bit of code to ErrorDocument that calls http_error only:

ErrorDocument 404 index.php?http_error=404 ErrorDocument 403 index.php?http_error=403

...and so on.

更多推荐

htaccess ErrorDocument 404重定向不工作

本文发布于:2023-10-31 19:21:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1547040.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重定向   工作   htaccess   ErrorDocument

发布评论

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

>www.elefans.com

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