diff --git a/server/routes.ts b/server/routes.ts index d2607ea..206e697 100644 --- a/server/routes.ts +++ b/server/routes.ts @@ -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 = { + "/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) => { try { 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[] = []; for (const p of staticPaths) { urls.push(` \n ${SITE}${p}\n daily\n ${p === "/" ? "1.0" : "0.7"}\n `); diff --git a/server/static.ts b/server/static.ts index 002e9ce..67c46cb 100644 --- a/server/static.ts +++ b/server/static.ts @@ -299,7 +299,30 @@ export function serveStatic(app: Express) { 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"); + if (!known) { + template = stripExistingMeta(template); + template = template.replace( + /[^<]*<\/title>/, + [ + '<title>Seite nicht gefunden | FOLX TV', + '', + ].join("\n ") + ); + res.status(404).set({ "Content-Type": "text/html" }).end(template); + return; + } res.status(200).set({ "Content-Type": "text/html" }).end(template); }); }