Created
March 15, 2020 07:58
-
-
Save moycat/71b86e5bc8bafb58aaad0288c758020b to your computer and use it in GitHub Desktop.
Why occupy a PAGE RULE when you can do it with a WORKER? For CloudFlare users.
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
addEventListener('fetch', event => { | |
event.respondWith(handleRequest(event.request)) | |
}) | |
/** | |
* Respond to the request | |
* @param {Request} request | |
*/ | |
async function handleRequest(request) { | |
url = new URL(request.url) | |
url.protocol = "https:" | |
url.hostname = url.hostname.replace(/^(www\.)/, "") | |
return Response.redirect(url, 301) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment