如何将PDF文件添加至已包含图片的Sitemap XML?
给Sitemap XML添加PDF文件的两种方法
PDF属于可被搜索引擎索引的资源,你可以通过以下两种方式将其加入sitemap.xml:
方法1:作为独立URL条目提交
把PDF当成单独的可索引资源,添加完整的<url>节点到<urlset>标签内部即可。若需要,还可补充更新时间、更新频率或优先级字段。
完整示例代码
<?xml version="1.0" encoding="UTF-8"?> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"> <!-- 你已有的原页面条目 --> <url> <loc>https://www.example.si/good</loc> <lastmod>2022-02-09</lastmod> <image:image> <image:loc>https://poster.domain.si/good.jpg</image:loc> </image:image> </url> <!-- 新增的PDF条目 --> <url> <loc>https://poster.example.si/good.PDF</loc> <!-- 可选:PDF的最后修改时间 --> <lastmod>2022-02-09</lastmod> <!-- 可选:设置更新频率,如monthly --> <changefreq>monthly</changefreq> <!-- 可选:设置优先级,范围0.0-1.0 --> <priority>0.7</priority> </url> </urlset>
方法2:作为原页面的关联资源提交
如果该PDF是原页面(https://www.example.si/good)的附属资源(比如页面的下载版),可以用<xhtml:link>标签关联两者,让搜索引擎明确它们的关系。这种方式需要在<urlset>中声明xhtml命名空间。
完整示例代码
<?xml version="1.0" encoding="UTF-8"?> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:xhtml="http://www.w3.org/1999/xhtml"> <!-- 原页面条目,新增xhtml:link关联PDF --> <url> <loc>https://www.example.si/good</loc> <lastmod>2022-02-09</lastmod> <image:image> <image:loc>https://poster.domain.si/good.jpg</image:loc> </image:image> <!-- 关联PDF资源 --> <xhtml:link rel="alternate" type="application/pdf" href="https://poster.example.si/good.PDF"/> </url> </urlset>
注意事项
- 确保PDF的URL是完整的绝对URL(包含
https://),不能使用相对路径 - 命名空间必须正确声明,否则搜索引擎可能无法识别扩展标签(如image或xhtml)
<lastmod>、<changefreq>、<priority>均为可选字段,按需添加即可
内容的提问来源于stack exchange,提问作者Jure
相关产品推荐
相关产品推荐

