Skip to content

Instantly share code, notes, and snippets.

@myobie
Created March 15, 2022 13:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save myobie/1df85767f03c89c9d9cd3bc9211b1d58 to your computer and use it in GitHub Desktop.
Save myobie/1df85767f03c89c9d9cd3bc9211b1d58 to your computer and use it in GitHub Desktop.
A cloudflare worker to remove the www subdomain and redirect
const status = 301
addEventListener('fetch', event => {
const url = new URL(event.request.url)
url.hostname = url.hostname.replace(/^www\./, '')
event.respondWith(Response.redirect(url.toString(), status))
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment