PHP或htaccess的进行动态URL页面去404项时,在数据库丢失 [英] PHP or htaccess make dynamic url page to go 404 when item is missing in DB

查看:139
本文介绍了PHP或htaccess的进行动态URL页面去404项时,在数据库丢失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

典型情形:

  1. 在DB项目displaied页面的http:// ... ITEM_ID = 467
  2. 用户1天的删除 该项目
  3. 在谷歌或用户 尝试访问的http:// ... ITEM_ID = 467
  4. 在PHP迪格斯到数据库,并认为项目不存在了,所以现在PHP必须告诉 谷歌/用户的项目没有通过404页眉和现有的。
  1. DB items are displaied in page http://...?item_id=467
  2. User one day deletes the item
  3. Google or a user attempts to access http://...?item_id=467
  4. PHP diggs into DB and sees items does not exist anymore, so now PHP must tell Google/user that item is not existing via a 404 header and page.

根据这个答案我undertstood没有办法通过PHP重定向到404 Apache的页面,除非发送在$ C C的404头+ $阅读和发送到客户端默认的404页的所有内容。

According to this answer I undertstood there is no way to redirect to 404 Apache page via PHP unless sending in code the 404 header + reading and sending down to client all the contents of your default 404 page.

在万阿英,蒋达清:我已经有一个的Apache解析自定义404 的shtml 页,所以obvioulsy我想简单地使用页面。 但是,如果我通过PHP读取的shtml页面就不会被Apache解析了

The probelm: I already have an Apache parsed custom 404.shtml page, so obvioulsy I would like to simply use that page. But if i read an shtml page via PHP it won't be parsed by Apache anymore.

所以,你有什么建议我做什么?

有可能一些诀窍,我可以用与htaccess的palying吗?

谢谢

推荐答案

嗯。两个想法浮现在脑海中:

Hmm. Two ideas come to mind:

  • 重定向到使用标题(位置:...)404页 - 这是不符合标准的行为,虽然。我会用这只能作为最后一根稻草

  • Redirect to the 404 page using header("Location:...") - this is not standards-compliant behaviour though. I would use that only as a last straw

取和输出使用Apache-解析SHTML文件的file_get_contents(http://mydomain.com/404.shtml); - 还没有确实的最佳方案,因为一个请求到Web服务器,但是,我认为,在大多数情况下可以接受的。

Fetch and output the Apache-parsed SHTML file using file_get_contents("http://mydomain.com/404.shtml"); - also not really optimal because a request is made to the web server but, I think, acceptable in most cases.

我怀疑有什么事情你可以在的.htaccess 做,因为PHP脚本中的任何重写规则都已经被解析后运行。

I doubt there is anything you can do in .htaccess because the PHP script runs after any rewrite rules have already been parsed.

这篇关于PHP或htaccess的进行动态URL页面去404项时,在数据库丢失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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