網路上有很多 sitemap 產生器,但產生出來的結果不如期望,為了做出更好的 sitemap 清單,我就自己作網站的 sitemap 產生器。
需要注意的小細節:
- sitemap 索引與 sitemap 中 url 引入的 xsd 是不一樣的。
 - 注意檔案大小 10MB 及筆數的上限 50,000 筆 URL。
 - 檔案如果很大最好用 gzip 壓縮,壓縮率會有 10 倍以上的落差。
 - 一定要用驗證器確認格式是否正確,在壓縮前請先確認格式,驗證器無法解析 gzip。
 - 一份 sitemap 中的 priority 值不能全部一樣,Google 會出現 warning。
 - 如果檔案已經封存不會變動,在 changefreq 的值最好設定為 never ,這樣會得到較好的文件索引。
 
Sitemap:
<?xml version='1.0' encoding='UTF-8'?>
<urlset 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9"
    url="http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"
    xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
>
   <url>
      <loc>http://www.example.com/</loc>
      <lastmod>2005-01-01</lastmod>
      <changefreq>monthly</changefreq>
      <priority>0.8</priority>
   </url>
   <url>
      <loc>http://www.example.com/catalog?item=12&desc=v_hawaii</loc>
      <lastmod>2005-01-01</lastmod>
      <changefreq>monthly</changefreq>
      <priority>0.8</priority>
   </url>
   <url>
      <loc>http://www.example.com/catalog?item=83&desc=v_usa</loc>
      <lastmod>2005-01-01</lastmod>
      <changefreq>monthly</changefreq>
      <priority>0.8</priority>
   </url>
</urlset>
Sitemap 索引檔:
<?xml version='1.0' encoding='UTF-8'?>
<sitemapindex 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9"
    url="http://www.sitemaps.org/schemas/sitemap/0.9/siteindex.xsd"
    xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
>
   <sitemap>
      <loc>http://www.example.com/sitemap1.xml.gz</loc>
      <lastmod>2004-10-01T18:23:17+00:00</lastmod>
   </sitemap>
   <sitemap>
      <loc>http://www.example.com/sitemap2.xml.gz</loc>
      <lastmod>2005-01-01</lastmod>
   </sitemap>
</sitemapindex>
Sitemap 驗證器:
Google Sitemap(s) Validator
參考文章:
Peter的部落格: Google Sitemaps 教學
網站登錄與提交sitemap(Yahoo!) @ 神鵰蝦
請問上面兩個XML有何不同?
回覆刪除索引檔是什麼?
請問兩個XML檔有何不同?
回覆刪除索引檔是什麼?
由於 sitemap.xml 有大小及數量上的限制,所以必要時需要分成好幾個,例如 sitemap_1.xml, sitemap_2.xml, sitemap_3.xml ...,而sitemap.xml 就必須是 index 的格式,去連結到其他分開 sitemap。
回覆刪除哈哈 我已經學會了
回覆刪除剛在整理書籤才發現當初有詢問
忘了回來看
抱歉 外加感謝