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:
+27
-1
@@ -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) => {
|
||||
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(` <url>\n <loc>${SITE}${p}</loc>\n <changefreq>daily</changefreq>\n <priority>${p === "/" ? "1.0" : "0.7"}</priority>\n </url>`);
|
||||
|
||||
Reference in New Issue
Block a user