Country based routing through workers not redirecting the internal pages

my main domain is i need to redirect to (for india) and (for uae) based on geo location routing using workers in cloudflare.

So i added a route and given the below script in workers

export default {
async fetch(request) {
* A map of the URLs to redirect to
* @param {Object} countryMap
const countryMap = {
IN: "",
AE: "",

  // 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 fetch(request);


The redirection is working based on country but when we call (Like this some pages are there) directly its not redirecting to and its internal pages(Like , Can any one have any idea about it?


You could easily set your redirection with a single dynamic Redirect Rule, since redirects trigger before Workers routes.

When incoming requests match...
( eq "" 
and equals "IN" 
and not starts_with(http.request.uri.path, "/in")


URL Redirect 
Type: Dynamic
Expression: concat("", http.request.uri.path)
Preserve query string: yes.

If you’d rather want to fix your Worker code, a better place to ask for help or :search: for a solution would be the Cloudflare Developers Discord channel.