, so WhatsApp / Facebook / Google see the real page. // Reached through .htaccess (the visitor's address stays course-details.html?slug=…). The page itself is unchanged. declare(strict_types=1); define('NA_ROOT', __DIR__); ini_set('display_errors', '0'); $page = ($_GET['p'] ?? '') === 'news' ? 'news' : 'course'; $file = NA_ROOT . ($page === 'news' ? '/news-details.html' : '/course-details.html'); $html = (string)@file_get_contents($file); header('Content-Type: text/html; charset=utf-8'); header('Cache-Control: no-cache, must-revalidate'); header('X-Content-Type-Options: nosniff'); header('X-Frame-Options: SAMEORIGIN'); function seo_out(string $html): void { echo $html; exit; } function seo_e(string $s): string { return htmlspecialchars($s, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); } function seo_clip(string $s, int $n = 200): string { $s = trim(preg_replace('/\s+/u', ' ', strip_tags(html_entity_decode($s, ENT_QUOTES, 'UTF-8'))) ?? ''); return mb_strlen($s) > $n ? rtrim(mb_substr($s, 0, $n - 1)) . '…' : $s; } try { require NA_ROOT . '/admin/inc/core.php'; $slug = mb_substr((string)($_GET['slug'] ?? ''), 0, 200); if ($html === '' || $slug === '' || !na_installed()) seo_out($html); $https = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') || (($_SERVER['HTTP_X_FORWARDED_PROTO'] ?? '') === 'https'); $host = preg_replace('/[^a-z0-9.\-:]/i', '', (string)($_SERVER['HTTP_HOST'] ?? 'newadmin.ae')) ?: 'newadmin.ae'; $site = ($https ? 'https://' : 'http://') . $host; $abs = function (string $u) use ($site): string { if ($u === '') return $site . '/images/branding/hero-classroom.jpg'; if (preg_match('~^https?://~i', $u)) return $u; return $site . '/' . ltrim(preg_replace('~^(\./|\.\./)+~', '', $u) ?? $u, '/'); }; $pdo = na_db(); $ld = null; if ($page === 'course') { $st = $pdo->prepare("SELECT * FROM courses WHERE slug = ? AND status = 'published' AND deleted_at IS NULL LIMIT 1"); $st->execute([$slug]); $r = $st->fetch(); if (!$r) seo_out($html); $tAr = trim((string)($r['title_ar'] ?? '')); $tEn = trim((string)$r['title']); $title = ($tAr !== '' && $tAr !== $tEn ? $tAr . ' | ' . $tEn : $tEn) . ' — New Admin Dubai'; $descAr = seo_clip((string)($r['description_ar'] ?? ''), 160); $descEn = seo_clip((string)($r['description'] ?? ''), 160); $desc = trim($descAr . ($descAr !== '' && $descEn !== '' ? ' — ' : '') . $descEn) ?: 'دورة في معهد نيو أدمن للتدريب المهني في دبي. A course at New Admin Institute, Dubai.'; $img = $abs((string)($r['image'] ?? '')); $url = $site . '/course-details.html?slug=' . rawurlencode((string)$r['slug']); $ld = ['@context' => 'https://schema.org', '@type' => 'Course', 'name' => $tEn, 'alternateName' => $tAr ?: null, 'description' => seo_clip((string)($r['description'] ?: ($r['description_ar'] ?? '')), 300) ?: $tEn, 'url' => $url, 'image' => $img, 'provider' => ['@type' => 'EducationalOrganization', 'name' => 'New Admin Institute', 'sameAs' => $site . '/']]; if ((int)($r['duration'] ?? 0) > 0) $ld['timeRequired'] = 'PT' . (int)$r['duration'] . 'H'; $ld = array_filter($ld, fn($v) => $v !== null && $v !== ''); } else { $st = $pdo->prepare("SELECT * FROM news WHERE slug = ? AND status = 'published' AND published_at <= NOW() LIMIT 1"); $st->execute([$slug]); $r = $st->fetch(); if (!$r) seo_out($html); $tAr = trim((string)$r['title_ar']); $tEn = trim((string)$r['title_en']); $title = ($tAr !== '' && $tEn !== '' && $tAr !== $tEn ? $tAr . ' | ' . $tEn : ($tAr ?: $tEn)) . ' — New Admin'; $desc = seo_clip((string)($r['excerpt_ar'] ?: $r['body_ar'] ?: $r['excerpt_en'] ?: $r['body_en']), 200) ?: 'أخبار معهد نيو أدمن. New Admin news.'; $img = $abs((string)($r['image'] ?? '')); $url = $site . '/news-details.html?slug=' . rawurlencode((string)$r['slug']); $job = ($r['type'] ?? '') === 'job'; $ld = ['@context' => 'https://schema.org', '@type' => $job ? 'Article' : 'NewsArticle', 'headline' => mb_substr($tAr ?: $tEn, 0, 110), 'image' => [$img], 'datePublished' => date('c', strtotime((string)$r['published_at']) ?: time()), 'mainEntityOfPage' => $url, 'publisher' => ['@type' => 'Organization', 'name' => 'New Admin Institute', 'logo' => ['@type' => 'ImageObject', 'url' => $site . '/images/logo.png']]]; } $set = function (string $html, string $re, string $tag): string { $n = 0; $out = preg_replace($re, $tag, $html, 1, $n); return $n ? (string)$out : str_replace('', $tag . '', $html); }; $html = $set($html, '~