Redirection based on user agent

6.Redirection based on user agent

I want to redirect visitors with a specific user agent (MSIE 8.0 for example) to a different page. It seems this is not possible with Cloudflare Page Rules. Is there any other way to achieve that using Cloudflare?


Dear <customer name>,

While Cloudflare Page Rules allow you to forward or redirect traffic to a different URL, redirecting based on the User-Agent HTTP request header is unfortunately not possible. More detailed information on Page Rules capabilities here:
https://developers.cloudflare.com/rules/page-rules/how-to/url-forwarding/

However, you can use Cloudflare Workers, which let you write custom logic for this purpose.

Below find an example Worker script to redirect visitors with specific user agent MSIE 8.0:

addEventListener('fetch', event => {
  event.respondWith(handleRequest(event.request))
})

async function handleRequest(request) {
  const userAgent = request.headers.get('User-Agent')

  if (userAgent && userAgent.includes('MSIE 8.0')) {
    return Response.redirect('https://your-fallback-page.com', 302) // Or 301 for permanent
  }

  // If not MSIE 8.0, continue with the original request
  return fetch(request)
}

For more details and examples of Cloudflare Workers and redirects, and how to deploy such Worker, please see:

In case you needĀ further assistance, I'm happy to help!

Best Regards,
Diogo Piteira