我有这个下面的代码,它做工精细如何压缩用PHP站点地图
header ("content-type: text/xml");
$xml = '<?xml version="1.0" encoding="UTF-8"?>';
$xml .= '<urlset xmlns="http://www.google.com/schemas/sitepam/0.84">';
$xml .= '<url><loc>'.SiteRoot.'</loc><changefreq>daily</changefreq><priority>1.0</priority></url>';
$xml .= '<url><loc>'.SiteRoot.'/directory</loc><changefreq>daily</changefreq><priority>0.9</priority></url>';
$Query = mysql_query ("SELECT link FROM `om` ORDER BY `link`");
while($row = mysql_fetch_array($Query)) {
$xml .= '<url>';
$xml .= '<loc>'.GenerateLink('link',$row['link']).'</loc>';
$xml .= '<changefreq>weekly</changefreq>';
$xml .= '<priority>0.8</priority>';
$xml .= '</url>';
}
$xml .= '</urlset>';
echo $xml;
当我尝试用MIME头压缩它
header('content-type: application/x-gzip');
header('Content-Disposition: attachment; filename="sitemap.xml.gz"');
浏览器下载.gz
文件,但它不是打开。 WinRAR的给我一个错误说:归档或者是在未知的格式或损坏
这是最后的代码:
// header ("content-type: text/xml");
header('content-type: application/x-gzip');
header('Content-Disposition: attachment; filename="sitemap.xml.gz"');
$xml = '<?xml version="1.0" encoding="UTF-8"?>';
$xml .= '<urlset xmlns="http://www.google.com/schemas/sitepam/0.84">';
$xml .= '<url><loc>'.SiteRoot.'</loc><changefreq>daily</changefreq><priority>1.0</priority></url>';
$xml .= '<url><loc>'.SiteRoot.'/directory</loc><changefreq>daily</changefreq><priority>0.9</priority></url>';
$Query = mysql_query ("SELECT link FROM `om` ORDER BY `link`");
while($row = mysql_fetch_array($Query)) {
$xml .= '<url>';
$xml .= '<loc>'.GenerateLink('link',$row['link']).'</loc>';
$xml .= '<changefreq>weekly</changefreq>';
$xml .= '<priority>0.8</priority>';
$xml .= '</url>';
}
$xml .= '</urlset>';
echo $xml;
对不起,但你为什么要压缩你的网站地图? – 2012-03-22 18:21:46
压缩大型站点地图是一种节省带宽的快捷方式,并得到大多数主要搜索引擎的支持。 – steveo225 2012-03-22 18:39:30
@ChibuezeOpata我的网站地图非常大。 – kamal 2012-03-22 18:49:09