Skip to main content

Bulk Redirects with Hono

Domain migration 301 redirect validation errors were occurring in Google Search Console, so we implemented a Hono-based redirect on Cloudflare Workers instead of using Cloudflare Bulk Redirects.

https://zenn.dev/jp/articles/2026-01-05-bulk-redirects-with-hono

โ†‘ ๆ—ฅๆœฌ่ชž็‰ˆ

Problemโ€‹

The "Change of Address" screen in Google Search Console showed "couldn't fetch page" errors, preventing domain migration completion for an extended period.

็ขบ่ชใ‚จใƒฉใƒผ:1 ไปถไปฅไธŠใฎๅฟ…้ ˆใฎใƒ†ใ‚นใƒˆใซๅคฑๆ•—ใ—ใพใ—ใŸใ€‚ใƒชใ‚ฏใ‚จใ‚นใƒˆใ‚’็ถš่กŒใงใใพใ›ใ‚“ใ€‚โŒ ใƒ›ใƒผใƒ ใƒšใƒผใ‚ธใ‹ใ‚‰ใฎ 301 ใƒชใƒ€ใ‚คใƒฌใ‚ฏใƒˆใ€‚ใƒšใƒผใ‚ธใ‚’ๅ–ๅพ—ใงใใพใ›ใ‚“ใงใ—ใŸใ€‚โœ… ไธกๆ–นใฎใ‚ตใ‚คใƒˆใฎ็ขบ่ชใ€‚ๆ‰€ๆœ‰ๆจฉใ‚’่จผๆ˜Žใ—ใพใ—ใŸใ€‚โš ๏ธ ใ‚ตใƒณใƒ—ใƒซใƒšใƒผใ‚ธใ‹ใ‚‰ใฎ 301 ใƒชใƒ€ใ‚คใƒฌใ‚ฏใƒˆใ€‚ใƒชใƒ€ใ‚คใƒฌใ‚ฏใƒˆใŒ่ฆ‹ใคใ‹ใ‚Šใพใ—ใŸใ€‚ใƒšใƒผใ‚ธใ‚’ๅ–ๅพ—ใงใใพใ›ใ‚“ใงใ—ใŸ

Solutionโ€‹

A Hono application deployed on Cloudflare Workers that provides 301 redirects. This implementation allows Google Search Console to successfully validate the domain migration.

Project Creationโ€‹

โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ > % npm create hono โ”‚
โ”‚ โ”‚
โ”‚ > npx โ”‚
โ”‚ > create-hono โ”‚
โ”‚ โ”‚
โ”‚ create-hono version 0.19.4 โ”‚
โ”‚ โœ” Target directory redirector โ”‚
โ”‚ โœ” Which template do you want to use? cloudflare-workers โ”‚
โ”‚ โœ” Do you want to install project dependencies? No โ”‚
โ”‚ โœ” Cloning the template โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

Select cloudflare-workers template.

Configurationโ€‹

Edit src/index.ts to set your destination domain.

import { Hono } from 'hono'

const DOMAIN = 'https://glre.dev'

const app = new Hono()

app.all('*', (c) => {
const { pathname, search } = new URL(c.req.url)
return c.redirect(`${DOMAIN}${pathname}${search}`, 301)
})

export default app

Cloudflare Deploymentโ€‹

npx wrangler login

2. Deployโ€‹

npm run deploy

Then configure the custom domain through the Cloudflare Workers console.

Verificationโ€‹

Test the redirect:

curl -I https://glre.tsei.jp/
# HTTP/2 301

After deployment, simply navigate to Google Search Console โ†’ Settings โ†’ Change of Address and select your new domain to complete the migration ๐ŸŽ‰

ใ“ใฎใ‚ตใ‚คใƒˆใฏ็พๅœจ็งป่กŒไธญใงใ™ใ€‚ใ“ใฎใ‚ตใ‚คใƒˆใ€‚ๆ–ฐใ—ใ„ใ‚ตใ‚คใƒˆใ€‚้–‹ๅง‹ๆ—ฅ