php 搜索引擎优化( 网站结构搜索引擎分为三部分:抓取、建索引、检索 )

优采云 发布时间: 2022-01-28 19:07

  php 搜索引擎优化(

网站结构搜索引擎分为三部分:抓取、建索引、检索

)

  

  网站结构

  搜索引擎分为三个部分:抓取、索引和检索。爬取就是通过爬虫软件自动爬取你的网站内容,并存储在搜索引擎的网页库中。索引就是对爬取的网页内容进行分析,建立倒排索引。检索就是让用户在搜索框中找到你的网页。

  爬取的过程是通过外部指向你的网站的链接或者你主动推送的*敏*感*词*链接开始广度和深度遍历,最后抓取你的整个网站,当然会继续跟着Retry抓取您的网页,如果找到新链接,它将继续抓取以使其保持最新。

  为了让搜索引擎抓取我们的网站,我们需要让我们的网站结构足够简单和清晰。建议尽量减少链接深度:爬虫优先考虑广度遍历,链接深度要小一些。更容易被快速爬取

  内部和外部链接

  爬虫通过超链接遍历 网站。根据排名算法,指向网站的链接越多,网站的排名就越高,所以尽量构建足够多的优质外链,这里说到优质,就不说了意味着外部链接越多越好,搜索引擎反垃圾邮件会丢弃过多的外部链接。增加网页中的链接数量。例如,您可以在 网站 的底部添加“最新的 文章”。如果你已经按照上一章一步步实现了我们的博客网站,那么你可以修改app /Resources/views/base.html.twig,在版权声明前添加:

  

最新文章

{% for article in latestblogs %}

{{ article.title }}

{% endfor %}

为你推荐

{% for article in recommends %}

{{ article.title }}

{% endfor %}

  并修改 src/AppBundle/Controller/BlogController.php 为 BlogController 添加如下方法:

  

public static function getLatestBlogs($contoller)

{

$blogPostRepository = $contoller->getDoctrine()->getRepository('AppBundle:BlogPost');

$blogposts = $blogPostRepository->findBy(array(), array('createTime' => 'DESC'), 5);

return $blogposts;

}

public static function getRecommends($contoller)

{

$blogPostRepository = $contoller->getDoctrine()->getRepository('AppBundle:BlogPost');

$allrecommends = $blogPostRepository->findBy(array(), array('createTime' => 'DESC'), 100);

$randList = BlogController::genRandList(0, sizeof($allrecommends), 5);

$recommends = array();

foreach ($randList as $index => $value) {

$recommends[] = $allrecommends[$index];

}

return $recommends;

}

public static function genRandList($min, $max, $num)

{

$num = min($num, $max-$min);

$map = array();

while (sizeof($map) < $num) {

$r = rand($min, $max-1);

$map[$r] = 1;

}

return $map;

}

  并修改listAction方法的render语句如下:

  

return $this->render('blog/list.html.twig', array('pagination' => $pagination,

'subject' => $subject,

'latestblogs' => BlogController::getLatestBlogs($this),

'recommends' => BlogController::getRecommends($this)));

  修改showAction方法的render语句如下:

  

public function showAction($blogId)

{

$this->blogPostRepository = $this->getDoctrine()->getRepository('AppBundle:BlogPost');

return $this->render('blog/show.html.twig', array('blogpost' => $this->blogPostRepository->find($blogId),

'latestblogs' => BlogController::getLatestBlogs($this),

'recommends' => BlogController::getRecommends($this)));

}

  同时修改src/AppBundle/Controller/DefaultController.php中indexAction方法的render语句,如下:

  

return $this->render('default/index.html.twig', array(

'subjects' => $subjects,

'blogcounts' => $this->getSubjectBlogCountMap($subjects),

'latestblogs' => BlogController::getLatestBlogs($this),

'recommends' => BlogController::getRecommends($this),

));

  看看效果:

  

  说明一下,这里的getLatestBlogs(latest 文章)是获取最近发布的几个文章,这里的getRecommends(recommended for you)其实是假的推荐,是有一定的随机性,这种随机性有一些好处,就是可以让搜索引擎每次爬取不同的结果,让它认为你的网站一直在更新,从而缩短爬取周期,更容易找到你的新链接

  内容质量

  网站的内容质量是搜索引擎优化的关键。搜索引擎基于文本,因此您应该尝试在页面中收录足够的文本信息。图片和js无疑会增加搜索引擎的分析。困难。努力上传优秀的原创文章肯定会受到搜索引擎的青睐。如果你只是转发,搜索引擎有办法知道谁是抄袭的原创,原创肯定会排在第一位

  主动提交

  百度站长平台为我们提供了一种主动提交链接的方式。注册账号后,即可获取自动提交代码并嵌入到网页中。一发布文章就可以传给百度。可以自己做,我的示例代码如下,仅供参考:

  

(function(){

var bp = document.createElement('script');

bp.src = '//push.zhanzhang.baidu.com/push.js';

var s = document.getElementsByTagName("script")[0];

s.parentNode.insertBefore(bp, s);

})();

0 个评论

要回复文章请先登录注册


官方客服QQ群

微信人工客服

QQ人工客服


线