Fixed shortlink redirections

This commit is contained in:
Kent Joseph T. Palima
2026-05-04 12:03:15 +08:00
parent ce66746573
commit ac21ba7031
+5 -9
View File
@@ -7,17 +7,14 @@ const { path } = Astro.params;
// 2. Check for our loop-breaker
const isLooping = Astro.url.searchParams.get('noloop') === 'true';
// 3. Define the shortlink target (ensuring we don't double the slash)
const shortlinkUrl = `https://upiecep.org/${path || ''}`;
// 4. SERVER-SIDE REDIRECT LOGIC
// If we didn't come from Short.io (noloop is missing), bounce back to the shortener once.
// 3. SERVER-SIDE REDIRECT LOGIC
if (!isLooping) {
return Astro.redirect(shortlinkUrl);
// We inline the URL here. This removes the "unused variable" warning
// and keeps the logic tight.
return Astro.redirect(`https://upiecep.org/${path || ''}`);
}
// 5. If we reach here, it's a confirmed 404 (Short.io already checked).
// Manually set the response status to 404 for SEO purposes.
// 4. If we reach here, it's a confirmed 404 (Short.io already checked).
Astro.response.status = 404;
---
@@ -33,7 +30,6 @@ Astro.response.status = 404;
<div class="button-group">
<a href="/" class="btn-main">Go to Homepage</a>
<!-- a href={shortlinkUrl} class="btn-shortlink">Try {shortlinkUrl}</a> -->
</div>
</section>
</Layout>