I have a website and I want to create a dynamic sitemap for it. I use Google App Engine with Python and Django.
I developed another website using PHP and the sitemap.xml was accessable because of this Rewrite Rule I wrote on the .htaccess of the Apache Server.
RewriteRule (.*)\.xml(.*) $1.php$2 [nocase]
The .xml file was generated like this:
$sql_select ="SELECT titulo, title, data_insercao FROM livros l ORDER BY titulo ASC";
$result = mysql_query($sql_select) or die(mysql_error());
while($row = mysql_fetch_array($result)) {
$titulo = $row['titulo'];
$title = $row['title'];
$data = $row['data_insercao'];
$sql_comentario ="SELECT data FROM comentarios WHERE livros_title = '" . $title . "' order by data desc LIMIT 0 , 1";
$result_comentario = mysql_query($sql_comentario) or die(mysql_error());
$row_comentario = mysql_fetch_array($result_comentario);
if($row_comentario){
$data = $row_comentario['data'];
}
$pieces = explode(" ", $data);
$data = $pieces[0];
$url_product = 'http://www.sinopsedolivro.net/livro/' . $title . '.html';
echo
' <url>
<loc>'.$url_product.'</loc>
<lastmod>'.$data.'</lastmod>
<changefreq>weekly</changefreq>
<priority>0.8</priority>
</url>
';
}
Is there any option for my case (GAE + Python) so when one access http://www.mydomain.com/sitemap.xml, he will receive from the server a .xml file with the dynamicaly content generate myself using python?
Sure, you can provide any response you want to any url with your application. Just map your controller to /sitemap.xml and write the code that outputs your xml in there. Don’t forget to set the mime type of the response to the right value.
If you are using django, you might want to read http://docs.djangoproject.com/en/dev/topics/http/urls/