Google
Edit File: sitemap-viral.php
<?php // Header XML agar Google Bot mengenalinya sebagai Sitemap header("Content-Type: application/xml; charset=utf-8"); // Konfigurasi URL dan Folder $base_url = "https://sman2siantar.sch.id/blog/"; $target_folder = "viral"; $full_path = $_SERVER['DOCUMENT_ROOT'] . "/blog/" . $target_folder; // File yang tidak ingin ditampilkan $ignore = array('.', '..', '.htaccess', 'index.php', 'config.php', 'wp-config.php', 'error_log'); echo '<?xml version="1.0" encoding="UTF-8"?>'; echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'; // 1. Tambahkan URL Utama Folder Viral echo ' <url> <loc>'.$base_url.$target_folder.'/</loc> <lastmod>'.date('Y-m-d').'</lastmod> <changefreq>hourly</changefreq> <priority>1.0</priority> </url>'; /** * Fungsi Rekursif Scan Folder Viral */ function scan_viral_content($dir, $base_url, $ignore) { if (!is_dir($dir)) return; $items = scandir($dir); foreach ($items as $item) { if (in_array($item, $ignore)) continue; $path = $dir . DIRECTORY_SEPARATOR . $item; if (is_dir($path)) { // Masuk ke subfolder di dalam /viral/ scan_viral_content($path, $base_url, $ignore); } else { // Filter ekstensi file yang valid untuk SEO $ext = pathinfo($item, PATHINFO_EXTENSION); if (in_array($ext, ['php', 'html', 'pdf', 'htm'])) { // Konversi path sistem menjadi URL website $web_path = str_replace($_SERVER['DOCUMENT_ROOT'], '', $path); $clean_url = "https://sman2siantar.sch.id" . str_replace('\\', '/', $web_path); // Ambil tanggal terakhir file diupdate $last_mod = date("Y-m-d", filemtime($path)); echo '<url>'; echo '<loc>' . htmlspecialchars($clean_url) . '</loc>'; echo '<lastmod>' . $last_mod . '</lastmod>'; echo '<changefreq>daily</changefreq>'; echo '<priority>0.8</priority>'; echo '</url>'; } } } } // Jalankan pemindaian otomatis if (file_exists($full_path)) { scan_viral_content($full_path, $base_url, $ignore); } echo '</urlset>'; ?>