-1

I've created a dynamic sitemap and linked it using a sitemapindex.(pasted all the code below).

Whenever I try to add the sitemapindex to bing or google for indexing google tells me that it is a correct sitemap but it tells me that my sitemap has an unsopported file format.

I store 10000 urls per sitemap.

These two lines are in my htaccess for rewriting php to xml:

RewriteRule ^sitemap_xml\.xml$ sitemap_xml.php [L]
RewriteRule ^sitemap_xml$ sitemap_xml.php [L]

sitemap index proccessed successfully

unsupported file format

sitemap.xml link

<?xml version="1.0"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
    <sitemap>
        <loc>https://www.kentekentje.nl/sitemap_xml.xml?cat=site</loc>
    </sitemap>
    <sitemap>
        <loc>https://www.kentekentje.nl/sitemap_xml.xml?cat=kenteken&amp;t=nul&amp;o=0</loc>
    </sitemap>
    <sitemap>
        <loc>https://www.kentekentje.nl/sitemap_xml.xml?cat=kenteken&amp;t=nul&amp;o=1</loc>
    </sitemap>
    <sitemap>
        <loc>https://www.kentekentje.nl/sitemap_xml.xml?cat=kenteken&amp;t=nul&amp;o=2</loc>
    </sitemap>
    <sitemap>
        <loc>https://www.kentekentje.nl/sitemap_xml.xml?cat=kenteken&amp;t=nul&amp;o=3</loc>
    </sitemap>
    <sitemap>
        <loc>https://www.kentekentje.nl/sitemap_xml.xml?cat=kenteken&amp;t=nul&amp;o=4</loc>
    </sitemap>
    <sitemap>
        <loc>https://www.kentekentje.nl/sitemap_xml.xml?cat=kenteken&amp;t=nul&amp;o=5</loc>
    </sitemap>
    <sitemap>
        <loc>https://www.kentekentje.nl/sitemap_xml.xml?cat=kenteken&amp;t=nul&amp;o=6</loc>
    </sitemap>
    <sitemap>
        <loc>https://www.kentekentje.nl/sitemap_xml.xml?cat=kenteken&amp;t=nul&amp;o=7</loc>
    </sitemap>
    <sitemap>
        <loc>https://www.kentekentje.nl/sitemap_xml.xml?cat=kenteken&amp;t=nul&amp;o=8</loc>
    </sitemap>
</sitemapindex>

sitemap_xml.php link

header("content-type: application/xml; charset=UTF-8");
$doc = new DomDocument('1.0', 'UTF-8');
if (isset($_GET['cat']) && !empty($_GET['cat'])) {
    $lastmod = date("Y-m-d") . "T" . date("H:i:s") . "+00:00";
    if ($_GET['cat'] == "kenteken" && isset($_GET['t']) && !empty($_GET['t'])) {
        if (isset($_GET['t']) && isset($_GET['o']) && is_numeric($_GET['o'])) {
            $exec = false;
            if (preg_match('/^[A-Z0-9]+$/', $_GET['t']) && $_GET['t'] != "C" && $_GET['t'] != "I" && $_GET['t'] != "Q") {
                $exec = true;
                $t = $_GET['t'];
            } elseif ($_GET['t'] == "nul") {
                $exec = true;
                $t = "0";
            }
            if ($exec === true) {
                $limit = 10000;

                $offset = $_GET['o'] * 10000;
                $kentekenlist_q = $mysqli->prepare("SELECT kenteken FROM RDW_" . $t . " LIMIT " . $limit . " OFFSET " . $offset);
                $kentekenlist_q->execute();
                $kentekenlist = $kentekenlist_q->get_result();
                $xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?>'
                       . '<urlset/>');
                $xml->addAttribute("xmlns", "http://www.sitemaps.org/schemas/sitemap/0.9");
                //echo $_GET['o'];
                while ($i = $kentekenlist->fetch_assoc()) {
                    $url = $xml->addChild("url");
                    $url->addChild("loc", $weburl . "kenteken/KL-45-RS/");
                    $url->addChild("lastmod", $lastmod);
                    $url->addChild("changefreq", "yearly");
                    $url->addChild("priority", "0.4");
                }
                echo $xml->asXML();
            }
        }
    }
}
  • 1
    **Warning:** You are wide open to [SQL Injections](https://php.net/manual/en/security.database.sql-injection.php) and should use parameterized **prepared statements** instead of manually building your queries. They are provided by [PDO](https://php.net/manual/pdo.prepared-statements.php) or by [MySQLi](https://php.net/manual/mysqli.quickstart.prepared-statements.php). Never trust any kind of input! Even when your queries are executed only by trusted users, [you are still in risk of corrupting your data](http://bobby-tables.com/). [Escaping is not enough!](https://stackoverflow.com/q/5741187) – Dharman Sep 30 '21 at 12:21
  • https://www.xml-sitemaps.com/validate-xml-sitemap.html says it can't find any problems. // I see `content-encoding: gzip`when I request the resource in my browser; that _should_ not be a problem, but I would perhaps test if the result changes when that gets deactivated. – CBroe Sep 30 '21 at 12:35
  • i fixed my prepared statement but still no indexing from google and bing – collin ter steege Sep 30 '21 at 13:23
  • @CBroe how do I disable gzip encoding? – collin ter steege Sep 30 '21 at 13:24
  • Depends on where it got enabled to begin with - the usual places are either in the PHP configuration, https://www.php.net/manual/en/outcontrol.configuration.php#ini.output-handler - or in the web server configuration. – CBroe Sep 30 '21 at 13:28

1 Answers1

0

A request for /sitemap_xml.xml?cat=kenteken&t=1&o=0 returns this:

<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"  
xsi="http://www.w3.org/2001/XMLSchema-instance"  
schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">

However, I believe it should be:

<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">

Aside:

for rewriting php to XML:

It's the other way round... it rewrites a request for a .xml file to PHP.

MrWhite
  • 43,179
  • 8
  • 60
  • 84