How to arrange sitemaps for main site and for blog

2019-07-09 12:22发布

问题:

I've got two websites: the main site and a blog that has posts that relate closely to the content of the main site. The blog is in the subdomain "blog."

wwww.example.com
blog.example.com

Content on the main site doesn't change that often, but content on the blog changes weekly. The blog is just a Wordpress site and capable of generating it's own sitemap.

I'm struggling to figure how to arrange the sitemaps.

I can think of two options, but I'm not sure what the best one is. Maybe there's a third option that I don't even know about.

Option 1

<sitemap>
  <loc>http://www.example.com</loc>
  <lastmod>2006-10-01T18:23:17+00:00</lastmod>

  <loc>http://www.example.com/about</loc>
  <lastmod>2006-10-01T18:23:17+00:00</lastmod>

  <loc>http://blog.example.com</loc>
  <lastmod>2006-10-01T18:23:17+00:00</lastmod>
</sitemap>

In this scenario, I suppose the search engines would crawl to the blog subdomain, but I'm not sure how they'd find the sitemap there. I'd just trust that the search engines find the site map based my uploading them directly via webmaster tools.

`

Option 2

The main sitemap could list multiple sitemaps.

 <sitemapindex xmlns="http://www.google.com/schemas/sitemap/0.84">
   <sitemap>
    <loc>http://www.example.com/sitemaps/sitemap.xml</loc>
    <lastmod>2006-10-01T18:23:17+00:00</lastmod>
   </sitemap>
   <sitemap>
     <loc>http://blog.example.com/sitemap.xml</loc>
     <lastmod>2006-10-01</lastmod>
  </sitemap>

 </sitemapindex>

What's the best practice here?

回答1:

Neither of your options is allowed.

You need a separate Sitemap file for each host (e.g., subdomain). And you can’t link to these Sitemap files from the same Sitemap index file, i.e., each host also needs its own Sitemap index file (if you want to use one).

About how search engines can find the Sitemaps (index) files, see my answer to the question What should be the name of the sitemap file for Google SEO?

Source

From the Sitemaps protocol specification about file location:

Note that this means that all URLs listed in the Sitemap must use the same protocol (http, in this example) and reside on the same host as the Sitemap. For instance, if the Sitemap is located at http://www.example.com/sitemap.xml, it can't include URLs from http://subdomain.example.com.

From the Sitemaps protocol specification about index files:

A Sitemap index file can only specify Sitemaps that are found on the same site as the Sitemap index file. For example, http://www.yoursite.com/sitemap_index.xml can include Sitemaps on http://www.yoursite.com but not on http://www.example.com or http://yourhost.yoursite.com.



标签: seo sitemap