
定時更新網站地圖的方法
sitemap.html (這個文件為系統自動生成,sitemap.php的克隆版)
sitemap.php (主要頁面,決定頁面的樣式等,完全=sitemap.html)
timeSitemap.php (為更新程序,生成html頁面。可在監控寶設置監控。)
sitemap.php為頁面文件,sitemap.html為sitemap.php的克隆版,監控寶設置定時監控timeSitemap.php文件,實現每15分鐘生成網站地圖,當然,頻率是按照監控寶的監控頻率來決定,如果地圖生成失敗,會返回404,監控寶會報警。sitemap.xml同理
下面共享代碼(用使用的mysql查詢等類為自己簡單封裝的數據庫類,這里就不展示了):
sitemap.php
/*
@ sitemap html版地圖
*/
// 引入數據庫操作類
require_once 'c/class.class.php';
// 引入系統參數
$config = require 'c/config.php';
?>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<title>網站地圖 - echo $config['web_title']; ?>title>
<meta name="keywords" content="">
<meta name="description" content="">
<link href="/css/bootstrap.min.css" rel='stylesheet' type='text/css'>
<link type="favicon" rel="shortcut icon" href="/favicon.ico" />
<link type="favicon" rel="icon" href="/favicon.ico" />
<style>
.table tr {
text-align: center;
}
a {
display: inline-block;
padding: 10px;
}style>
head>
<body>
//
$cons = new con();
$consSql = "select * from urls order by id desc";
$consQuery = $cons->query($consSql);
// >> 總數量
$consNum = mysql_num_rows($consQuery);
?>
<div class="container">
<hr>
<div style='text-align:center;height:35px;line-height:35px;font-weight:bold;'>
共 echo $consNum; ?>條數據div><div style='text-align:center;'>本頁面每15分鐘更新一次
div>
hr>
本站鏈接:<a href="http://bba.fun">bba.fun短網址a><a href="http://bba.fun/page/api">api接口a><a href="http://bba.fun/sitemap.html">網站地圖a>
<br>
生成鏈接:
<br>
// >> 顯示總數量
echo "";
// >> 開始循環取出
while($rows = mysql_fetch_array($consQuery)){
echo "".$rows['short_url']."";
}
?>
<div style='text-align:center;height:35px;line-height:35px;font-weight:bold;'>2017© <a href=""> echo $config['web_title']; ?>a>div><hr>
div>
body>
html>
timeSitemap.php
/*
@ 定時更新網站地圖
*/
// 定義獲取的url
$url = "http://bba.fun/sitemap.php";
// 定網站地圖名字
$name = "sitemap.html";
// 獲取源碼
$html = file_get_contents($url);
// 寫入html
$write = file_put_contents($name,$html);
if($write){
header("HTTP/1.1 200");
}else {
header("HTTP/1.1 404");
}
?>
原標題:定時更新網站地圖的方法(百度seo優化分享)