- Add metadata to login and login-verify pages to prevent indexing. - Update robots.txt to disallow additional sensitive paths. - Enhance sitemap generation to filter by city and include accurate last modified dates. - Refactor canonical URL generation to support multi-domain architecture, ensuring self-canonicalization for city domains. - Remove deprecated CanonicalHandler component and streamline canonical URL handling. - Introduce safe JSON-LD output to prevent XSS vulnerabilities. - Add payment layout with appropriate metadata to prevent indexing. - Conduct a comprehensive technical SEO audit and implement necessary fixes across the application.
51 lines
2.0 KiB
JavaScript
51 lines
2.0 KiB
JavaScript
import { headers } from "next/headers";
|
|
|
|
// استراتژی چند-دامنهای: هر دامنهی شهری یک property مستقل و first-class است.
|
|
// هر صفحه self-canonical روی هاست جاری میگیرد؛ هرگز به دامنهی اصلی canonical نمیدهیم.
|
|
|
|
const DEFAULT_HOST = "nobat724.com";
|
|
|
|
export function normalizeHost(rawHost) {
|
|
return (rawHost || DEFAULT_HOST).toLowerCase().replace(/^www\./, "");
|
|
}
|
|
|
|
export function buildCanonicalPath(pathname) {
|
|
let path = (pathname || "/").split("?")[0].split("#")[0];
|
|
if (!path.startsWith("/")) path = `/${path}`;
|
|
if (path.length > 1 && path.endsWith("/")) path = path.slice(0, -1);
|
|
return path;
|
|
}
|
|
|
|
export function buildCanonicalUrl(host, pathname) {
|
|
const normalizedHost = normalizeHost(host);
|
|
const hostname = normalizedHost.replace(/:\d+$/, "");
|
|
const protocol =
|
|
hostname.endsWith("localhost") || hostname === "127.0.0.1" ? "http" : "https";
|
|
return `${protocol}://${normalizedHost}${buildCanonicalPath(pathname)}`;
|
|
}
|
|
|
|
// origin هاست جاری (بدون trailing slash) — برای ساخت URLهای مطلق در JSON-LD و متادیتا
|
|
export async function getRequestOrigin() {
|
|
try {
|
|
const headersList = await headers();
|
|
return buildCanonicalUrl(headersList.get("host"), "/").replace(/\/$/, "");
|
|
} catch {
|
|
return "https://nobat724.com";
|
|
}
|
|
}
|
|
|
|
export async function getCanonicalUrl() {
|
|
try {
|
|
const headersList = await headers();
|
|
const host = headersList.get("host");
|
|
const pathname = headersList.get("x-pathname");
|
|
// مسیرهای خارج از matcher میدلور (panel/dashboard/login) این هدر را ندارند —
|
|
// آنها noindex هستند و نباید canonical جعلی به ریشه بگیرند.
|
|
if (!pathname) return null;
|
|
return buildCanonicalUrl(host, pathname);
|
|
} catch (error) {
|
|
console.error("Error generating canonical URL:", error);
|
|
return null;
|
|
}
|
|
}
|