View Full Version : Sitemap autoupdate <lastmod> ?
Is it possible to auto update the <lastmod> tag since my sites are updated daily?
Halfdeck
2007-08-02, 07:17 PM
One way is to render sitemap.xml using PHP
(.htaccess)
AddType application/x-httpd-php .xml
Then inside your XML file:
<?php
$lastmod = date('Y-m-d');
$header .= "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
$header .= "<urlset xmlns=\"http://www.google.com/schemas/sitemap/0.84\"
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
xsi:schemaLocation=\"http://www.google.com/schemas/sitemap/0.84
http://www.google.com/schemas/sitemap/0.84/sitemap.xsd\">";
echo $header;
?>
then include $lastmod in XML:
<url><loc>http://www.example.com</loc>
<lastmod><? echo $lastmod; ?></lastmod></url>
Problem with this approach is all your XML files in the root directory will not show correctly in many browsers.
thanks a lot will try it |thumb
unfortunally google could not read my sitemap :( this is how it looks like
<?php
$lastmod = date('Y-m-d');
$header .= "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
$header .= "<urlset xmlns=\"http://www.google.com/schemas/sitemap/0.84\"
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
xsi:schemaLocation=\"http://www.google.com/schemas/sitemap/0.84
http://www.google.com/schemas/sitemap/0.84/sitemap.xsd\">";
echo $header;
?>
<url>
<loc>http://www.hentaiprince/</loc>
<lastmod><? echo $lastmod; ?></lastmod>
<changefreq>hourly</changefreq>
<priority>0.9</priority>
</url>
... and so on
</urlset>
Halfdeck
2007-08-10, 01:53 PM
You need to wrap the list of urls in <urlset>. You have </urlset> at the end but no opening <urlset>.
If that fix doesn't work, try validating it using an XML validator. Also use a http header checker to make sure the PHP page is generating the right code.
vBulletin® v3.8.1, Copyright ©2000-2026, Jelsoft Enterprises Ltd.