本文介绍了设置一个页面,拦截所有尚未存在的页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 大家好, 我想设置我的网站,以便当一个页面的请求不存在时,传输将被传递给我指定的某个页面。对于 实例,如果用户请求 http://mysite.com / pages / contact 即 不是有效的页面或目录,请求递交给 http://mysite.com/pages/display.php 或类似内容。 我想知道最好的方法是什么 - 我知道我可以使用 ..htaccess文件重定向404错误,但我宁愿不给404 $ b首先是$ b错误。有更好的/其他方式吗?我似乎记得 已经阅读了另一种方式...但我似乎无法记住... 这是在LAMP环境中,并且不需要移植到Windows 或任何其他网络服务器。 任何帮助将不胜感激! 他, -Josh 解决方案 它被称为404处理程序,但它不必返回http错误 状态。在404处理程序脚本中,您可以返回404( 默认状态)或选择执行您可能想到的任何其他操作, 就像重定向到正确的URL如果是小错别字。客户 永远不会发现它是由404处理程序处理的...... 这实际上更像一个网络服务器问题,它真的取决于在 您正在使用的网络服务器上。你提到.htaccess,所以我会假设 apache。 编辑httpd.conf文件(/etc/httpd/conf/httpd.conf 并寻找: #ErrorDocument 404 /missing.html 取消注释并更改网址你想要什么。 重新启动服务器 - gburnore @databasix dot com ------------------------------------------------- -------------------------- 你看起来如何取决于你去哪里。 ------------------------------------------------- -------------------------- Gary L. Burnore | Y?3oY3T3oY33Y?oY3T3oY3Y3T3oY3YY?3 | Y?3oY3T3oY33Y?oY3T3oY3Y3T3oY3YY?3 DataBasix | Y?3oY3T3oY33Y?oY3T3oY3Y3T3oY3YY?3 | Y?3 3 4 1 4 2 Y3T3 6 9 0 6 9 Y?3 黑色直升机维修Svcs部门|官方购买证明 =================== ========================== ===== ========================= 想要一个?得到一个! http://signup.databasix.com === =============================================== === ====================== 它被称为404处理程序,但它不必返回http错误状态。在404处理程序脚本中,您可以返回404(默认状态)或选择执行您可能提出的任何其他操作,例如,如果出现小错别字,则重定向到正确的URL。客户永远不会发现它是由404处理程序处理的...... 好的。 还有其他方法吗?这些是什么?他们是否提供某种优势?b $ b b?有没有理由不去404处理程序路线? Hi All, I would like to setup my site so that when a page is request that does notexist, transfer is instead passed to a certain page that I specify. Forinstance, if the user requests http://mysite.com/pages/contact and that isnot a valid page or directory, then the request is handed to http://mysite.com/pages/display.php or something like that. I am wondering what the best way to do this is - I know that I could use an..htaccess file to redirect 404 errors, but I would rather not give a 404error in the first place. Is there a better/other way? I seem to rememberhaving read about another way... but I can''t seem to remember... This is in a LAMP environment, and does not need to be portable to Windowsor any other webserver. Any help would be greatly appreciated! His,-Josh 解决方案 It''s called a 404 handler, but it doens''t have to return an http errorstatus. In the 404 handler script you can either return a 404 (thedefault status) or choose to do anything else you might come up with,like redirecting to the correct url in case of small typos. The clientwill never find out it was handled by the 404 handler... This is really more of a webserver question and it really depends onthe webserver you''re using. You mention .htaccess, so I''ll assumeapache. edit the httpd.conf file (/etc/httpd/conf/httpd.conf and look for this: #ErrorDocument 404 /missing.htmlUncomment it and change the url to what you want. restart the server--gburnore@databasix dot com---------------------------------------------------------------------------How you look depends on where you go.---------------------------------------------------------------------------Gary L. Burnore | Y?3oY3T3oY33Y?oY3T3oY3Y3T3oY3YY?3| Y?3oY3T3oY33Y?oY3T3oY3Y3T3oY3YY?3DataBasix | Y?3oY3T3oY33Y?oY3T3oY3Y3T3oY3YY?3| Y?3 3 4 1 4 2 Y3T3 6 9 0 6 9 Y?3Black Helicopter Repair Svcs Division | Official Proof of Purchase================================================== =========================Want one? GET one! http://signup.databasix.com================================================== ========================= It''s called a 404 handler, but it doens''t have to return an http error status. In the 404 handler script you can either return a 404 (the default status) or choose to do anything else you might come up with, like redirecting to the correct url in case of small typos. The client will never find out it was handled by the 404 handler... Ah ok. Are there other ways to do it? What are they? Do they provide advantagesof some sort? Is there any reason to not go the 404 handler route? 这篇关于设置一个页面,拦截所有尚未存在的页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 11-02 06:31