I am trying to write a redirect rule that will redirect the user only if the match the locales: en-us, zh-tw, fr-be. If they do not match these locales, the rule will ignore them. The user will be redirected to another site with just their country code.
foo.com/en-us/bar => foo2.com/us/bar2 foo.com/zh-tw/bar => foo2.com/tw/bar2 foo.com/fr-be/bar => foo2.com/be/bar2
This is my attempt, but I'm not sure how to extract the last two characters from $1:
^/?foo.com/([en-us|zh-tw|fr-be])/bar$ => http://foo2.com/$1/bar2 ^/?foo.com/[en-(us)|zh-(tw)|fr-(be)]/bar$ => http://foo2.com/$1/bar2
Try: ^/?foo.com/(en)-(us)|(zh)-(tw)|(fr)-(be)(/bar)$
$0 --> foo2.com/$2$4$6$7
Tested in PHP. Working for all test cases and excludes other combinations.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments