SEO: canonical, sitemap.xml, robots.txt, JSON-LD, noindex admin

This commit is contained in:
Cedric Abonnel
2026-05-12 01:19:38 +02:00
parent ca6fcefe51
commit 3a5ae2631d
7 changed files with 139 additions and 3 deletions
+3
View File
@@ -16,6 +16,9 @@ RewriteRule ^feed/?$ /feed.php [L,QSA]
RewriteRule ^rss/?$ /feed.php [L,QSA]
RewriteRule ^rss\.xml$ /feed.php [L,QSA]
# Sitemap
RewriteRule ^sitemap\.xml$ /sitemap.php [L]
# Ajoute .php si le fichier correspondant existe
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI}.php -f
RewriteRule ^(.+?)/?$ /$1.php [L,QSA]
+4
View File
@@ -21,6 +21,10 @@ $action = $_GET['action'] ?? 'list';
$uuid = $_GET['uuid'] ?? '';
$slug = $_GET['slug'] ?? '';
$_noindexActions = ['create', 'edit', 'admin', 'categories', 'diff', 'add_files', 'import_image', 'import_image_step2', 'sources', 'profile', 'delete_file', 'delete_external_link', 'rename_category', 'delete_category', 'toggle_private_category'];
$metaRobots = in_array($action, $_noindexActions, true) ? 'noindex, nofollow' : null;
unset($_noindexActions);
// ─── Extraction de métadonnées depuis une URL ────────────────────────────────
function fetchUrlMeta(string $url): array
{
+16
View File
@@ -0,0 +1,16 @@
User-agent: *
Disallow: /?action=edit
Disallow: /?action=create
Disallow: /?action=admin
Disallow: /?action=delete
Disallow: /?action=diff
Disallow: /?action=categories
Disallow: /?action=add_files
Disallow: /?action=import_image
Disallow: /?action=sources
Disallow: /?action=profile
Disallow: /login
Disallow: /logout.php
Disallow: /oidc/
Sitemap: https://varlog.a5l.fr/sitemap.xml
+49
View File
@@ -0,0 +1,49 @@
<?php
declare(strict_types=1);
define('BASE_PATH', realpath(__DIR__ . '/../'));
require_once BASE_PATH . '/src/helpers.php';
require_once BASE_PATH . '/config/config.php';
require_once BASE_PATH . '/src/ArticleManager.php';
$articles = new ArticleManager(BASE_PATH . '/data');
$privateCats = $articles->getPrivateCategories();
$published = array_filter($articles->getAll(true), static function (array $a) use ($privateCats): bool {
$cat = trim($a['category'] ?? '');
if ($cat !== '' && in_array($cat, $privateCats, true)) {
return false;
}
if (strtotime((string)($a['published_at'] ?? '')) > time()) {
return false;
}
return true;
});
header('Content-Type: application/xml; charset=UTF-8');
header('X-Robots-Tag: noindex');
echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . "\n";
// Homepage
echo ' <url>' . "\n";
echo ' <loc>' . htmlspecialchars(rtrim(APP_URL, '/') . '/') . '</loc>' . "\n";
echo ' <changefreq>daily</changefreq>' . "\n";
echo ' <priority>1.0</priority>' . "\n";
echo ' </url>' . "\n";
foreach ($published as $article) {
$loc = htmlspecialchars(rtrim(APP_URL, '/') . '/post/' . rawurlencode($article['slug'] ?? ''));
$lastmod = date('Y-m-d', strtotime((string)($article['updated_at'] ?? $article['published_at'] ?? 'now')));
echo ' <url>' . "\n";
echo ' <loc>' . $loc . '</loc>' . "\n";
echo ' <lastmod>' . $lastmod . '</lastmod>' . "\n";
echo ' <changefreq>monthly</changefreq>' . "\n";
echo ' <priority>0.8</priority>' . "\n";
echo ' </url>' . "\n";
}
echo '</urlset>' . "\n";