学做网站培训课程介绍

当前位置:

ZBLOG实现指定分类下文章蜘蛛抓取正常用户404

ZBLOG实现指定分类下文章蜘蛛抓取正常用户404,就是指定某个栏目下的文章,搜索蜘蛛抓取时是正常的,但普通用户浏览是404。可以通过判断代码来实现。

ZBLOG文章页模板路径:(修改后,在后台--主题管理重启一下模板,或者在主机里修改一下模板文件夹名,再改回来)

/zb_users/theme/模板名/template/single.php

代码如下:


<?php die();?>
{if $article.Category.ID =='8'}

{php}
$useragent = addslashes(strtolower($_SERVER['HTTP_USER_AGENT']));
$bot='';
if (strpos($useragent, 'googlebot')!== false){$bot = 'Google';}
elseif (strpos($useragent,'mediapartners-google') !== false){$bot = 'Google Adsense';}
elseif (strpos($useragent,'baiduspider') !== false){$bot = 'Baidu';}
elseif (strpos($useragent,'sogou spider') !== false){$bot = 'Sogou';}
elseif (strpos($useragent,'sogou web') !== false){$bot = 'Sogou web';}
elseif (strpos($useragent,'48.0.2564.116') !== false){$bot = 'baidu';}
elseif (strpos($useragent,'sosospider') !== false){$bot = 'SOSO';}
elseif (strpos($useragent,'360spider') !== false){$bot = '360Spider';}
elseif (strpos($useragent,'yahoo') !== false){$bot = 'Yahoo';}
elseif (strpos($useragent,'msn') !== false){$bot = 'MSN';}
elseif (strpos($useragent,'msnbot') !== false){$bot = 'msnbot';}
elseif (strpos($useragent,'sohu') !== false){$bot = 'Sohu';}
elseif (strpos($useragent,'yodaoBot') !== false){$bot = 'Yodao';}
elseif (strpos($useragent,'twiceler') !== false){$bot = 'Twiceler';}
elseif (strpos($useragent,'ia_archiver') !== false){$bot = 'Alexa_';}
elseif (strpos($useragent,'iaarchiver') !== false){$bot = 'Alexa';}
elseif (strpos($useragent,'slurp') !== false){$bot = '雅虎';}
elseif (strpos($useragent,'bot') !== false){$bot = '其它蜘蛛';}
{/php}

{if $bot !=''}

{template:header}
{if $article.Type==ZC_POST_TYPE_ARTICLE}
{template:post-single}
{else}
{template:post-page}
{/if}
{template:footer}

{else}
<p style="padding:50px;text-align:center;">404 NO FOUND!</p>

{/if}

{else}

{template:header}
{if $article.Type==ZC_POST_TYPE_ARTICLE}
{template:post-single}
{else}
{template:post-page}
{/if}
{template:footer}

{/if}

如果需要某个分类下的文章源代码存在,但TITLE为404,可以使用以下的代码:


{if $article.Category.ID =='8'}
<script>
$('title').html('404 Not Found');
$('body').html('<!DOCTYPE html>\n' +
'<html lang="en">\n' +
'<head>\n' +
'    <meta charset="UTF-8">\n' +
'    <meta name="viewport" content="width=device-width, initial-scale=1.0">\n' +
'    <title>404</title>\n' +
'    <style> * { max-width: initial !important; } </style>\n' +
'</head>\n' +
'<body style="margin: 0;padding: 0;">\n' +
// '    <div style="width: 100%;height: 100%;">\n' +
// '        <img src="/deleted/skin/4.png" alt="" style="background-size: 100% 100%;background-repeat: no-repeat;width: 100%;height: 100%;">\n' +
// '    </div>\n' +
'    <center><h1>404 Not Found</h1></center>\n' +
'    <hr><center>nginx</center>\n' +
'</body>\n' +
'</html>');
</script>
{/if}

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

相关教程

  • 现在很多网站都安装了SSL证书来实现加密访问,SSL证书一般是申请后可以使用一年,一年到期后再次申请重新布署。但有些站长会遇到这样的情况,网站旧
  • WordPress程序里的某个PHP文件,如果想连接数据库,一般需要填写数据库名、数据库用户、密码等信息,如下:<?php$conn=mysqli_connect(&qu
  • 我们做网站一般都是做自适应结构,不同用户使用不同的浏览设备可以浏览不同的版面的网站。但有时为了特殊的要求,我们不希望自己的网站手机端自适应,
  • 我们制作网站前台提交发布界面时,富文本编辑器常常使用kindeditor 编辑器,kindeditor 编辑器支持用户上传图片和附件,通常情况下编辑器是不限制附件
  • notepad是一款比较好用的网页编辑软件,学建站网张启亚老师也一直在用notepad。notepad有一个比较实用的功能就是它会自动保存之前打开的文件列表,但
  • 在PHP中,数组是一种非常常见且重要的数据类型。在使用数组时,通常需要不断地向数组中添加新的元素,以满足我们的需求。那么,在PHP中,如何向已有数
  • 网站中的滑动选择开关是比较常见的开关选择器,方便用户可以打开或者关闭某个参数。效果如下图:下面分享一下网站中的滑动选择开关的制作代码:HTM
  • 我们有些同学做的是下载类网站,如果使用普通的A标签来下载,很容易被别采集,这样会严重影响网站的运营。那么怎么隐藏下载地址呢?让资源的下载地址
  • 在https页面中,如果调用了http资源,那么浏览器就会抛出一些错误。我们可以通过一个meta 标签来限制网站调用http资源,自动将http替换成https资源。
  • 我们做网站时,往往需要制作图片列表,但有时每个图片宽度设置一样后,高度会不一样,这就导致了网站版面排序混乱。如下图:怎么解决这种排序混乱的