SEO language URI redirection + existing directories

Hello,

I currently have URI built to have URI like
website.my/en
made to send the content from ‘website.my’ in the en language.

My Ngingx conf is as follows:
location ~* “^/[a-z]{2}(/.*)?$” {
rewrite “^/([a-z]{2})/?$” /index.php?lang=$1 last;
rewrite “^/([a-z]{2})(/[^.]+)$” $2/index.php?lang=$1 last;
rewrite “^/([a-z]{2})(/.+)$” $2 last;
}

I also have some 2-letters top-level directories which I want to send
with
the highest priority.

I would like that
website.my/ab
checks if /ab directory (or file) exists and:

  • process its content as usual if it’s the case
  • redirects through the language rules if it’s not

Is there a way to make some conditional rewrite based on the try_files
directive?

Thanks,

B. R.