Skip to content

Instantly share code, notes, and snippets.

Created March 15, 2022 13:32
What would you like to do?
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