怎么样才能做好百度站点的主动推送?
主动推送网站链接给百度以加快网站收录,是一种提高网站抓取效率的方法。比如通过API提交,网站管理员可以主动向百度推送新内容,减少等待搜索引擎自动抓取的时间,从而让新页面更快被索引和收录。
让网站被百度收录是提升网站在百度搜索引擎中曝光率的关键步骤。百度作为中国最大的搜索引擎,拥有大量的用户流量,网站被其收录后,才能在搜索结果中展示,进而带来流量。
以下是一个主动推送的例子,帮助你提高网站在百度中的收录率和排名。
// 创建 public function actionCreate() { $model = new PostForm(); // 定义场景 $model->setScenario(PostForm::SCENARIOS_CREATE); if ($model->load(Yii::$app->request->post()) && $model->validate()) { if (! $model->create()) { // echo 123;exit; Yii::$app->session->setFlash('warning', $model->_lastError); } else { //文章创建之后推送到百度的接口 $this->postTobaidu($model->id); return $this->redirect([ 'post/view', 'id' => $model->id ]); } } // 查询分类 $cat = CatModel::getAllCats(); return $this->render('create', [ 'model' => $model, 'cat' => $cat ]); } /** * 百度主动推送 */ public function postTobaidu($id){ /* $urls = array( 'http://laro.cn/post/view?id=18', 'http://www.example.com/2.html', ); */ $api = 'http://data.zz.baidu.com/urls?site=laro.cn&token=yourtoken'; $ch = curl_init(); $options = array( CURLOPT_URL => $api, CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_POSTFIELDS => "http://laro.cn/post/view?id=".$id, CURLOPT_HTTPHEADER => array('Content-Type: text/plain'), ); curl_setopt_array($ch, $options); $result = curl_exec($ch); return $result; }