技术文摘

懒人必备:帝国CMS的sitemap文件伪静态为xml

作者:雨祺   发表于:
浏览:103次    字数:2092  原创
级别: 站长   总稿: 68 篇,  月稿: 0
帝国实用小技巧:php方式的sitemap文件伪静态为xml
php方式的sitemap文件伪静态为xml,懒人必备,一次设置上传就可,不必经常生成sitemap的xml
具体设置是:
1、php写成sitemap格式,下面是我的一个例子,最重要的是
  1. header("Cache-Control: no-store, no-cache, must-revalidate"); 
  2. header('Content-type: text/xml'); 
这两句,应该是设置文件为xml属性,不添加好像搜索引擎不认;
2、伪静态设置里加上
  1. rewrite ^/sitemap/sitemap_([0-9]+).xml$  /sitemap/sitemap.php?page=$1; 
  2. rewrite ^/sitemap/sitemap.xml$  /sitemap/sitemap.php; 
最后就开始写sitemap.php这个文件的代码呢,代码如下:
  1. <?php 
  2. header("Cache-Control: no-store, no-cache, must-revalidate"); 
  3. require("../e/class/connect.php"); 
  4. require("../e/class/db_sql.php"); 
  5. require("../e/data/dbcache/class.php"); 
  6. $link=db_connect(); 
  7. $empire=new mysqlquery(); 
  8. $surl="http://www.***.com/"; //改你的域名 
  9. $per_page = 5000;  
  10. $xml='<?xml version="1.0"  encoding="UTF-8" ?>'."rn"
  11. if(isset($_GET['page'])){ 
  12.     $xml.='<urlset 
  13.     xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" 
  14.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  15.     xmlns:mobile="http://www.baidu.com/schemas/sitemap-mobile/1/" 
  16.     xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 
  17.     http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">'."rn"; 
  18.     if(intval($_GET['page'])==0){ 
  19.         $xml.='<url>'."rn"
  20.         $xml.='  <loc>'.$surl.'</loc>'."rn"
  21.         $xml.='  <lastmod>'.date('c').'</lastmod>'."rn"
  22.         $xml.='  <changefreq>always</changefreq>'."rn"
  23.         $xml.='  <priority>1.00</priority>'."rn"
  24.         $xml.='</url>'."rn"
  25.  
  26.         $queryc="select classid from {$dbtbpre}enewsclass"
  27.         $sqlc=$empire->query($queryc); 
  28.         while($c=$empire->fetch($sqlc)){ 
  29.             $xml.='<url>'."rn"
  30.             $xml.='  <loc>'.$surl.'list_'.$c[classid].'.html</loc>'."rn";//栏目页链接方式根据自己具体设置 
  31.             $xml.='  <lastmod>'.date('c').'</lastmod>'."rn"
  32.             $xml.='  <changefreq>always</changefreq>'."rn"
  33.             $xml.='  <priority>0.95</priority>'."rn"
  34.             $xml.='</url>'."rn"
  35.         } 
  36.     }else
  37.         $start=(intval($_GET['page'])-1)*$per_page; 
  38.         $query="select id,newstime from {$dbtbpre}ecms_news order by newstime desc limit $start,$per_page"
  39.         $sql=$empire->query($query);; 
  40.         while($r=$empire->fetch($sql)){ 
  41.             $xml.='<url>'."rn"
  42.             $xml.='  <loc>'.$surl.'detail_'.$r[id].'.html</loc>'."rn";//内容页链接方式根据自己具体设置 
  43.             $xml.='  <lastmod>'.date('c',$r['newstime']).'</lastmod>'."rn"
  44.             $xml.='  <changefreq>daily</changefreq>'."rn"
  45.             $xml.='  <priority>0.80</priority>'."rn"
  46.             $xml.='</url>'."rn"
  47.         } 
  48.     } 
  49.     $xml.='</urlset>'
  50. }else
  51.     $totalqueryt="select count(*) as total from {$dbtbpre}ecms_news"
  52.     $num=$empire->gettotal($totalqueryt); 
  53.     $allpage = ceil($num/$per_page); 
  54.     $xml.='<sitemapindex>'."rn"
  55.     for($i=0;$i<=$allpage;$i++){ 
  56.         $xml.='<sitemap>'."rn"
  57.         $xml.='  <loc>'.$surl.'sitemap/sitemap_'.$i.'.xml</loc>'
  58.         $xml.="rn".'</sitemap>'."rn"
  59.     } 
  60.     $xml.='</sitemapindex>'
  61. header('Content-type: text/xml'); 
  62. ob_clean(); 
  63. echo $xml; 
  64. exit; 
  65. ?> 

【审核人:站长】

收藏   加好友   生成海报   分享
点赞(0)
打赏
Tags: xml CMS 文件 sitemap 必备 静态 懒人 帝国
评论(0人参与,0条评论) 雨祺
0/0
  • 请先说点什么
    最新评论

    发布者资料

    热门文章

    技术文摘

    查看更多技术文摘
    首页
    栏目
    搜索
    会员
    投稿