是否允许指定 ?id=1
sitemap_index.xml 中的 URL 的一部分,<loc>
标签?
我想创建一个动态站点地图。
我通过添加这行 AddType application/x-httpd-php .xml
使 php 在 .xml 文件中执行到.htaccess,现在我想创建一个静态站点地图索引文件和一个动态站点地图文件,这是我写的代码:
sitemap_index.xml:
<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<sitemap>
<loc>http://example.com/sitemap.xml?id=1</loc>
<lastmod>2014-07-06</lastmod>
</sitemap>
<sitemap>
<loc>http://example.com/sitemap.xml?id=2</loc>
<lastmod>2014-07-06</lastmod>
</sitemap>
<sitemap>
<loc>http://example.com/sitemap.xml?id=3</loc>
<lastmod>2014-07-06</lastmod>
</sitemap>
<!-- ..And so on -->
</sitemapindex>
站点地图.xml:
<?php
(empty($_GET['id'])) ? $_GET['id'] = 0 : settype($_GET['id'], 'int');
$result = '<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
$from = $_GET['id']*45000;
$to = $_GET['id']*45000+45000;
for ($i = $from; $i < $to; $i++) {
$result .= '
<url>
<loc>http://example.com/page.php?id=' . $i . '</loc>
<lastmod>2014-07-06</lastmod>
<changefreq>weekly</changefreq>
</url>';
}
$result .= "\n</urlset>";
echo $result;
?>
最佳答案
是的。任何有效的 url 都可以在站点地图中。您的示例显示的带有查询字符串的网址是常见且正常的,通常在除最基本站点的站点地图之外的所有站点中都可以找到。
是的。您可以使用带有查询字符串的站点地图网址。 [似乎任何有效的 url 都可以工作] (. https://webmasters.stackexchange.com/questions/49589/sitemap-xml-file-extension-does-it-have-to-be-xml)。尝试将您的网址提交给 Google 网站站长工具,您可以验证它是否有效。
关于php - 在 <loc> 标记、站点地图索引文件中包含查询的 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24599555/