Country redirection with request url


I’m using CloudFlare country redirection code, How can add url request to end of url.

for example
Visitor request url is but the script redirect to ttps://

CloudFlare country redirection code;

 * Returns a redirect determined by the country code
 * @param {Request} request
async function redirect(request) {
  // Use the cf object to obtain the country of the request
  // more on the cf object:
  const country =

  if (country != null && country in countryMap) {
    const url = countryMap[country]
    return Response.redirect(url)
  else {
    return await fetch(request)
 * A map of the URLs to redirect to
 * @param {Object} countryMap
const countryMap = {
  US: "",
  DE: "",

async function handleRequest(request) {
  return redirect(request)

addEventListener("fetch", event => {

Are you trying to redirect to:

If so, you see that countryMap in the code, this specifics where the redirects go. That’s why it goes to

Side note: you probably want the pathname from the URL and append that to the redirection, currently it won’t do that.

1 Like

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.