Created
March 28, 2022 02:05
-
-
Save ambanmba/3bdfc7ad6f8937b8ed7a1508fd8030e0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const statusCode = 301; | |
async function handleRequest(request) { | |
const url = new URL(request.url); | |
const hostname = url.hostname; | |
const { pathname, search } = url; | |
const askhostname = /(greenllgold.com)/; | |
const gethostname = `greeniigold.com`; | |
const newbase = hostname.replace(askhostname, gethostname); | |
const destinationURL = 'https://' + newbase + pathname + search; | |
return Response.redirect(destinationURL, statusCode); | |
} | |
addEventListener('fetch', async event => { | |
event.respondWith(handleRequest(event.request)); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example to silently redirect a typo domain to the correct domain using a Cloudflare Worker