Skip to content

Commit d12635a

Browse files
committed
feat(seo): add 404 page with redirect for old URL patterns
1 parent b7fce49 commit d12635a

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

src/pages/404.astro

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
---
2+
import BaseHead from '../components/BaseHead.astro';
3+
import Footer from '../components/Footer.astro';
4+
import Header from '../components/Header.astro';
5+
import { SITE_TITLE } from '../consts';
6+
---
7+
8+
<!doctype html>
9+
<html lang="ko">
10+
<head>
11+
<BaseHead title={`404 - ${SITE_TITLE}`} description="페이지를 찾을 수 없습니다." />
12+
<script is:inline>
13+
(function() {
14+
const path = window.location.pathname;
15+
16+
// 옛 URL 패턴: /YYYY/MM/DD/slug/ → /blog/slug/
17+
const koMatch = path.match(/^\/(\d{4})\/(\d{2})\/(\d{2})\/(.+?)\/?$/);
18+
if (koMatch) {
19+
const slug = koMatch[4];
20+
window.location.replace('/blog/' + slug + '/');
21+
return;
22+
}
23+
24+
// 옛 URL 패턴: /en/YYYY/MM/DD/slug/ → /en/blog/slug/
25+
const enMatch = path.match(/^\/en\/(\d{4})\/(\d{2})\/(\d{2})\/(.+?)\/?$/);
26+
if (enMatch) {
27+
const slug = enMatch[4];
28+
window.location.replace('/en/blog/' + slug + '/');
29+
return;
30+
}
31+
})();
32+
</script>
33+
<style>
34+
main {
35+
width: 100%;
36+
max-width: 800px;
37+
margin: 0 auto;
38+
padding: 100px 40px;
39+
text-align: center;
40+
}
41+
h1 {
42+
font-size: 4rem;
43+
margin: 0 0 16px 0;
44+
color: #333;
45+
}
46+
p {
47+
color: #666;
48+
font-size: 1.1rem;
49+
margin-bottom: 32px;
50+
}
51+
a {
52+
color: #111;
53+
text-decoration: underline;
54+
}
55+
a:hover {
56+
color: #555;
57+
}
58+
</style>
59+
</head>
60+
<body>
61+
<Header />
62+
<main>
63+
<h1>404</h1>
64+
<p>페이지를 찾을 수 없습니다.</p>
65+
<a href="/">홈으로 돌아가기</a>
66+
</main>
67+
<Footer />
68+
</body>
69+
</html>

0 commit comments

Comments
 (0)