Nginx redirect outdated browser to a specific page

Hi,
I would like to add a custom nginx config for redirect all outdated browser to a specific page.

I’ll use this simple code:

location / {
  if ($http_user_agent ~ "MSIE 6.0" ) {
    set $browser-version outdated;
  }

  if ($http_user_agent ~ "MSIE 7.0" ) {
    set $browser-version outdated;
  }

  if ($http_user_agent ~ "MSIE 8.0" ) {
    set $browser-version outdated;
  }

  if ($http_user_agent ~ "MSIE 9.0" ) {
    set $browser-version outdated;
  }

  if ($browser-version = outdated) {
    rewrite  ^  /interact-guests-increase-revenues break;
  }
}

Where can I put this code ? I tried in includes.d without success, I got a duplicate location error…

Any idea ?

Here’s an idea straight from the documentation: https://roots.io/trellis/docs/nginx-includes/

@julianfox I imagine the “duplicate location error” is a result of your location / { } block (in includes.d) duplicating the location / { } block in wordpress.conf. The two location blocks specify the same location_match or uri (i.e., /) and are within the same server block.

I think this means that the current Trellis Nginx includes feature doesn’t facilitate adding a new location / { } block, i.e., a location whose location_match or uri is /. I’m guessing you’ll need to handle outdated browsers using some means other than Nginx.

If you’re set on using Nginx, you could devise an improvement to the Trellis Nginx includes. (Another missing feature is to accommodate new server blocks.)

An alternative (not recommended) might be to maintain for your project a fork that adds your above conditions/rewrite to the beginning of the location block in wordpress.conf. But it’s no fun to modify core files and try to maintain the modifications without future trouble .

Thanks for your answer,
Even when I add directly the redirection to the beginning of the location block in wordpress.conf I got an error 404 on the outdated browsers.