" text sitting in an .xml // file, since web servers don't run PHP inside .xml — it was almost // certainly being served to Google as broken XML). This regenerates the // sitemap from the real database on every request: homepage, static // pages, every published blog post, and every active product — so // everything you actually publish becomes discoverable by search engines. // /.htaccess rewrites the public /sitemap.xml URL to this file. // ============================================================ require_once __DIR__ . '/db.php'; header('Content-Type: application/xml; charset=utf-8'); $host = $_SERVER['HTTP_HOST'] ?? 'vintageug.duckdns.org'; $base = 'https://' . $host; function sm_url($loc, $lastmod, $changefreq, $priority) { return " \n" . " " . htmlspecialchars($loc) . "\n" . " " . htmlspecialchars($lastmod) . "\n" . " {$changefreq}\n" . " {$priority}\n" . " \n"; } $today = date('Y-m-d'); $xml = "\n"; $xml .= "\n"; // ---- Homepage + static pages ---- $xml .= sm_url("{$base}/", $today, 'daily', '1.0'); foreach (['blog', 'reviews', 'compare'] as $staticPage) { $xml .= sm_url("{$base}/{$staticPage}.php", $today, 'weekly', '0.6'); } // ---- Blog posts (published only) ---- try { $stmt = $pdo->query("SELECT id, created_at, updated_at FROM blog_posts WHERE is_published = 1 ORDER BY created_at DESC LIMIT 500"); foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $post) { $lastmod = !empty($post['updated_at']) ? $post['updated_at'] : $post['created_at']; $xml .= sm_url("{$base}/blog.php?id=" . (int) $post['id'], date('Y-m-d', strtotime($lastmod)), 'monthly', '0.7'); } } catch (Throwable $e) { // blog_posts table/columns may not match on every install — skip quietly, homepage still ships. } // ---- Products (active/in-catalog only) ---- try { $stmt = $pdo->query("SELECT id, updated_at, created_at FROM products WHERE is_active = 1 ORDER BY id DESC LIMIT 1000"); foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $product) { $lastmod = !empty($product['updated_at']) ? $product['updated_at'] : ($product['created_at'] ?? $today); $xml .= sm_url("{$base}/index.php?product=" . (int) $product['id'], date('Y-m-d', strtotime($lastmod)), 'weekly', '0.8'); } } catch (Throwable $e) { // Same defensive skip as above. } $xml .= ""; echo $xml;