如何将此链接(以下)重定向到404错误页?
我生成一个SEO友好链接,通常产品都有url,如blabla.com/ links /sub/product.html。
这页没有任何错误。它只显示空白内容。我的意思是,我可以看到静态文本,如类别名称标题,但没有动态分类名称旁边,因为url是错误的,不能从db获得记录。页面不显示动态内容,而是显示静态内容
感谢帮助!!谢谢
发布于 2009-11-24 14:29:15
如果查询不产生任何行,则可以将报头设置为404 - not,并将其重定向到404页。
例如:
<?php
//$rows is the num_rows of the query
if ($rows > 0) {
//your code here
} else {
header("HTTP/1.1 404 Not Found");
header("Location: 404.html");
exit();
}
?>发布于 2009-11-24 14:24:52
您应该使用.htaccess来捕获错误:
ErrorDocument 400 /errors/400.html
ErrorDocument 401 /errors/401.html
ErrorDocument 403 /errors/403.html
ErrorDocument 404 /errors/404.html
ErrorDocument 500 /errors/500.htmlApache现在将知道它需要加载其中一个页面,这取决于发生了什么错误。相反,您可以为动态解决方案提供一个php脚本(例如,404.php)。
这意味着http://www.blabla.com/category/sub/.html将显示一条错误消息,服务器将生成一个错误头(在本例中为404),因此搜索引擎不会对其进行爬行。
在您的http根目录中创建一个名为.htaccess的文件并在其中粘贴代码,就可以使用此代码。.htaccess不是文件扩展,而是文件本身。
更多信息可以是在这里发现的
发布于 2009-11-24 16:58:02
不要重定向!重定向(30x)不同于发送404!只需发送正确的状态代码和错误文档:
if (!$documentFound) {
header($_SERVER['SERVER_PROTOCOL'].' 404 Not Found', true, 404);
readfile('error404.html');
exit;
}https://stackoverflow.com/questions/1790367
复制相似问题