diff --git a/src/pages/404.astro b/src/pages/[...path].astro similarity index 79% rename from src/pages/404.astro rename to src/pages/[...path].astro index 239ca94..da6f39f 100644 --- a/src/pages/404.astro +++ b/src/pages/[...path].astro @@ -1,22 +1,24 @@ --- import Layout from '../layouts/Layout.astro'; -// 1. Capture the exact path the user tried to visit (e.g., "/hihi") -const currentPath = Astro.url.pathname; +// 1. Get the path from the URL params +const { path } = Astro.params; + +// 2. Check for our loop-breaker const isLooping = Astro.url.searchParams.get('noloop') === 'true'; -// 2. Build the correct shortlink URL without the "www." -const shortlinkUrl = `https://upiecep.org${currentPath}`; +// 3. Define the shortlink target (ensuring we don't double the slash) +const shortlinkUrl = `https://upiecep.org/${path || ''}`; -// 3. SERVER-SIDE REDIRECT LOGIC -// If 'noloop' is NOT present, it means the user came here directly (e.g. via www). -// We redirect them to the short domain to see if a link exists there. +// 4. SERVER-SIDE REDIRECT LOGIC +// If we didn't come from Short.io (noloop is missing), bounce back to the shortener once. if (!isLooping) { return Astro.redirect(shortlinkUrl); } -// If we are here, it means isLooping is TRUE. -// Short.io already checked and didn't find a link, so we show the 404 page. +// 5. If we reach here, it's a confirmed 404 (Short.io already checked). +// Manually set the response status to 404 for SEO purposes. +Astro.response.status = 404; --- @@ -26,12 +28,11 @@ if (!isLooping) {

We checked both the website and our shortlink database, but - {currentPath} doesn't seem to exist. + /{path} doesn't seem to exist.

Go to Homepage - Try {shortlinkUrl}