Search the Database (Mysql) and create Sitemap in parts (PHP)

1

I have the following code to generate sitemap:

<?php
header("Content-type: text/xml");
echo'<?xml version=\'1.0\' encoding=\'UTF-8\'?>';
echo'   <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" 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/sitemap.xsd">';

include 'conexao.php';

$sql = mysql_query("select aluno, matricula, aprovacao from faculdade");

while ($string = mysql_fetch_array($sql)){?>

<?php

$dataaprovacao = $string['aprovacao'];
$newDate = date("Y-m-d", strtotime($dataaprovacao));
?>

<url>
<loc>https://site.com.br/<?echo $string['aluno'];?>/<?echo $string['matricula'];?></loc>
<lastmod><?echo $newDate;?></lastmod>
</url>

<?php } ?> 
</urlset>

I would like to save this response in several files (sitemap1.xml, sitemap2.xml etc.) with 50 thousand urls each. Is it possible?

    
asked by anonymous 18.09.2018 / 03:48

1 answer

0

I think so. You can create a file called sitemap.php that gets a $ _GET and work inside that file. Then just enter a code similar to: RewriteRule ^sitemap([0-9]+).xml$ sitemap.php?id=$1 within your .htacess file to have a custom dynamic url. In other words, your system would get /sitemap1.xml in the URL and your code would interpret it as /sitemap.php?id=1 .

    
18.09.2018 / 17:09