Fixed shortlink redirections
This commit is contained in:
+16
-10
@@ -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.
|
||||
---
|
||||
|
||||
<Layout title="Page Not Found | UP IECEP">
|
||||
<section class="not-found-section">
|
||||
<h1>404</h1>
|
||||
<h2>Oops! We couldn't find that page.</h2>
|
||||
|
||||
<p>
|
||||
The link you clicked might be broken, or the page may have been removed.
|
||||
</p>
|
||||
<p class="shortlink-hint">
|
||||
<strong>Looking for a shortlink?</strong> If you typed "www" before the link, it might have broken it. Try the direct shortlink below!
|
||||
We checked both the website and our shortlink database, but
|
||||
<strong>{currentPath}</strong> doesn't seem to exist.
|
||||
</p>
|
||||
|
||||
<div class="button-group">
|
||||
<!-- Button 1: Back to Homepage -->
|
||||
<a href="/" class="btn-main">Go to Homepage</a>
|
||||
|
||||
<!-- Button 2: Dynamic Shortlink Attempt -->
|
||||
<a href={shortlinkUrl} class="btn-shortlink">
|
||||
Try {shortlinkUrl}
|
||||
</a>
|
||||
<!-- We still keep this just in case they want to try again manually -->
|
||||
<a href={shortlinkUrl} class="btn-shortlink">Try {shortlinkUrl}</a>
|
||||
</div>
|
||||
</section>
|
||||
</Layout>
|
||||
|
||||
Reference in New Issue
Block a user