我创建页面http://omenorpreco.com/sitemap_index.xml谷歌阅读并识别我的所有页面。
但是,当访问此页面时,XML不会以XML模式打开。
如果我查看这个页面的来源,复制并通过我桌面上的一个文件,然后在brownser中打开,这个文件会正确打开
怎么了?
<?php
echo "<?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 http://www.sitemaps.org/schemas/sitemap/0.9/siteindex.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<?php
header("Content-Type: application/xml; charset=UTF-8");
$sql = "SELECT ceil(count(*)/5000) as total FROM `produto_price`";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
?>
<sitemap>
<loc>http://omenorpreco.com/sitemap-categoria.xml</loc>
<lastmod><?php echo date('Y-m-d'); ?></lastmod>
</sitemap>
<?php
for($i = 1; $i <= $row['total']; $i++) : ?>
<sitemap>
<loc>http://omenorpreco.com/sitemap-<?php echo $i ; ?>.xml</loc>
<lastmod><?php echo date('Y-m-d'); ?></lastmod>
</sitemap>
<?php
endfor
?>
</sitemapindex>
我的.htaccess文件重定向到url_amigavel.php
url_amigavel.php包括文件sitemap_index.php
试试这个
<?php
header("Content-Type: application/xml; charset=UTF-8");
echo "<?xml version='1.0' encoding='UTF-8'?>";
$sql = "SELECT ceil(count(*)/5000) as total FROM `produto_price`";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
?>
<sitemapindex xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/siteindex.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<sitemap>
<loc>http://omenorpreco.com/sitemap-categoria.xml</loc>
<lastmod><?php echo date('Y-m-d'); ?></lastmod>
</sitemap>
<?php for($i = 1; $i <= $row['total']; $i++): ?>
<sitemap>
<loc>http://omenorpreco.com/sitemap-<?php echo $i ; ?>.xml</loc>
<lastmod><?php echo date('Y-m-d'); ?></lastmod>
</sitemap>
<?php endfor; ?>
</sitemapindex>