cfw-language-redirector icon indicating copy to clipboard operation
cfw-language-redirector copied to clipboard

🧑💬 A simple worker to redirect your landing-pages to the language-specific versions.

Cloudflare Workers Language Redirector

Deploy to CF-Workers

This project can be used to run in front of Cloudflare Pages or any static site. It takes incoming requests to the homepage and redirects them to /{the users language}. This is made to be used in conjunktion with something like gatsby-plugin-react-i18next for GatsbyJS so your users will have a fast redirect when landing on your site, but you can also have this worker run in front of any other "traditional" site to cut down in initial response times when users have to be redirected to a localized version of the page first.

How to use?

The simple way

Click the following button:

Deploy to Cloudflare Workers

After that continue with "How to configure?".

The hard way

To manually deploy this worker you will need to fork this repo and add CF_ACCOUNT_ID and CF_API_TOKEN to your repository actions secrets, containing your Cloudflare Account ID and an API-Key created with the "Edit Cloudflare Workers"-preset, so the GitHub Action will work.

How to configure?

Configuring cfw-language-redirector

To get started open config.js by clicking the little pen icon on GitHub or by cloning the repo to your local computer and editing the file.

You will then need to fill in the default language, the supported languages, and the paths the redirector should be active at. The paths should be your landing pages, so users will be redirected fast on those.

Configuring Cloudflare

Visit the Cloudflare Workers Zone settings to have the worker run in front of your site by setting up Worker Routes.