404 in sitemap: sitemap je kazal na /news /video /galerie, ki jih router ne pozna (soft 404); 301 preusmeritve za stare poti (/empfang, /news, /video, /galerie, /about ...); neznana pot vrne pravi HTTP 404 namesto 200
This commit is contained in:
parent
ca47bc8698
commit
808e9a5438
@ -116,10 +116,36 @@ export async function registerRoutes(
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Stare oziroma logicne poti, ki jih React router ne pozna. Brez tega
|
||||||
|
// uporabnik in Google dobita 404 (npr. /empfang/, ki je bil v obtoku).
|
||||||
|
const LEGACY_REDIRECTS: Record<string, string> = {
|
||||||
|
"/empfang": "/empfang-folx-tv",
|
||||||
|
"/empfang-folx": "/empfang-folx-tv",
|
||||||
|
"/news": "/category/News",
|
||||||
|
"/nachrichten": "/category/News",
|
||||||
|
"/video": "/videos",
|
||||||
|
"/galerie": "/gallery",
|
||||||
|
"/ueber": "/ueber-uns",
|
||||||
|
"/about": "/ueber-uns",
|
||||||
|
"/contact": "/kontakt",
|
||||||
|
"/rezept": "/rezepte",
|
||||||
|
"/horoscope": "/horoskop",
|
||||||
|
};
|
||||||
|
app.get(Object.keys(LEGACY_REDIRECTS), (req, res) => {
|
||||||
|
const to = LEGACY_REDIRECTS[req.path.replace(/\/+$/, "") || "/"];
|
||||||
|
if (to) return res.redirect(301, to);
|
||||||
|
return res.redirect(301, "/");
|
||||||
|
});
|
||||||
|
|
||||||
app.get("/sitemap.xml", async (_req, res) => {
|
app.get("/sitemap.xml", async (_req, res) => {
|
||||||
try {
|
try {
|
||||||
const articles = await storage.getArticles();
|
const articles = await storage.getArticles();
|
||||||
const staticPaths = ["/", "/aktuelles", "/news", "/video", "/galerie", "/horoskop", "/rezepte", "/kontakt", "/impressum", "/datenschutz"];
|
// POZOR: tu smejo biti samo poti, ki jih pozna React router v App.tsx.
|
||||||
|
// Prej so bile "/news", "/video", "/galerie" — teh poti ni, zato je Google
|
||||||
|
// dobival soft 404. Prave so "/category/News", "/videos", "/gallery".
|
||||||
|
const staticPaths = ["/", "/aktuelles", "/category/News", "/videos", "/gallery",
|
||||||
|
"/horoskop", "/rezepte", "/empfang-folx-tv", "/ueber-uns",
|
||||||
|
"/kontakt", "/impressum", "/datenschutz"];
|
||||||
const urls: string[] = [];
|
const urls: string[] = [];
|
||||||
for (const p of staticPaths) {
|
for (const p of staticPaths) {
|
||||||
urls.push(` <url>\n <loc>${SITE}${p}</loc>\n <changefreq>daily</changefreq>\n <priority>${p === "/" ? "1.0" : "0.7"}</priority>\n </url>`);
|
urls.push(` <url>\n <loc>${SITE}${p}</loc>\n <changefreq>daily</changefreq>\n <priority>${p === "/" ? "1.0" : "0.7"}</priority>\n </url>`);
|
||||||
|
|||||||
@ -299,7 +299,30 @@ export function serveStatic(app: Express) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Neznana pot mora vrniti PRAVI 404, sicer Google dobi soft 404 (HTTP 200
|
||||||
|
// z naslovnico). Seznam mora ustrezati potem v client/src/App.tsx.
|
||||||
|
const KNOWN = [
|
||||||
|
/^\/$/, /^\/search\/?$/, /^\/article\//, /^\/category\//, /^\/aktuelles\/?$/,
|
||||||
|
/^\/videos\/?$/, /^\/gallery\/?$/, /^\/horoskop(\/|$)/, /^\/rezepte\/?$/,
|
||||||
|
/^\/empfang-folx-tv\/?$/, /^\/ueber-uns\/?$/, /^\/impressum\/?$/,
|
||||||
|
/^\/datenschutz\/?$/, /^\/kontakt\/?$/, /^\/admin(\/|$)/,
|
||||||
|
];
|
||||||
|
const cleanPath = url.split("?")[0].split("#")[0];
|
||||||
|
const known = KNOWN.some((re) => re.test(cleanPath));
|
||||||
|
|
||||||
let template = await fs.promises.readFile(indexPath, "utf-8");
|
let template = await fs.promises.readFile(indexPath, "utf-8");
|
||||||
|
if (!known) {
|
||||||
|
template = stripExistingMeta(template);
|
||||||
|
template = template.replace(
|
||||||
|
/<title>[^<]*<\/title>/,
|
||||||
|
[
|
||||||
|
'<title>Seite nicht gefunden | FOLX TV</title>',
|
||||||
|
'<meta name="robots" content="noindex, follow" />',
|
||||||
|
].join("\n ")
|
||||||
|
);
|
||||||
|
res.status(404).set({ "Content-Type": "text/html" }).end(template);
|
||||||
|
return;
|
||||||
|
}
|
||||||
res.status(200).set({ "Content-Type": "text/html" }).end(template);
|
res.status(200).set({ "Content-Type": "text/html" }).end(template);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user