Skip to content

Commit 5525cf6

Browse files
committed
feat: add middleware for 301 redirect from legacy domain to canonical domain
1 parent a93da4e commit 5525cf6

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* 301 redirect from the legacy applirank.com domain to reqcore.com.
3+
*
4+
* If the old domain's DNS still points to this server (via Cloudflare or Railway),
5+
* this middleware redirects all traffic to the new domain with a permanent 301,
6+
* preserving the original path and query string so Google transfers link equity.
7+
*
8+
* Also handles non-www → www normalization if ever needed, and ensures HTTPS.
9+
*/
10+
const LEGACY_HOSTS = new Set(['applirank.com', 'www.applirank.com'])
11+
const CANONICAL_ORIGIN = 'https://reqcore.com'
12+
13+
export default defineEventHandler((event) => {
14+
const host = getRequestHeader(event, 'host')?.split(':')[0]?.toLowerCase()
15+
if (!host || !LEGACY_HOSTS.has(host)) return
16+
17+
const url = getRequestURL(event)
18+
const target = `${CANONICAL_ORIGIN}${url.pathname}${url.search}`
19+
20+
return sendRedirect(event, target, 301)
21+
})

0 commit comments

Comments
 (0)