diff --git a/src/pages/404.astro b/src/pages/404.astro index b087f2f..239ca94 100644 --- a/src/pages/404.astro +++ b/src/pages/404.astro @@ -3,30 +3,36 @@ import Layout from '../layouts/Layout.astro'; // 1. Capture the exact path the user tried to visit (e.g., "/hihi") const currentPath = Astro.url.pathname; +const isLooping = Astro.url.searchParams.get('noloop') === 'true'; // 2. Build the correct shortlink URL without the "www." const shortlinkUrl = `https://upiecep.org${currentPath}`; + +// 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. +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. ---

404

Oops! We couldn't find that page.

+

- The link you clicked might be broken, or the page may have been removed. -

-