<?php
require_once 'config.php';
require_once 'admin/blog-functions.php';

// Get the blog ID from the query parameter
$blog_id = isset($_GET['id']) ? (int)$_GET['id'] : 0;

if ($blog_id <= 0) {
    header("Location: /A+/01/blogs.php");
    exit;
}

// Get blog from database
$blog = getBlogById($link, $blog_id);

if (!$blog || empty($blog['slug'])) {
    header("Location: /A+/01/blogs.php");
    exit;
}

// Redirect to SEO-friendly URL with 301 status (permanent redirect)
$seo_url = "/A+/01/blog/" . $blog['slug'];
header("Location: $seo_url", true, 301);
exit;
?>