tags:

views:

30

answers:

2

I have am working on a multi language file. My urls look something like this:

http://www.mydomain.com/en/about/info
http://www.mydomain.com/nl/about/info

Now I use a small regex script that redirect the user when they use a link without language. The script looks like this:

preg_match('~^/[a-z]{2}/~', $_SERVER['REQUEST_URI']

This finds out is there is a language set en|nl|de etc. This works fine on all links except for these:

http://www.mydomain.com/en
http://www.mydomain.com/nl

There is no trailing slash so the regex can not find the given values.

Anyone know a fix for this?

+1  A: 
preg_match('~^/[a-z]{2}(?:/)?~', $_SERVER['REQUEST_URI'])
erenon
this will match 2 chars after every slash.
serg
Don't know if it matters, but that will also match `http://www.mydomain.com/enfoo`.
Alan Moore
No this match will not work for my situation
Saif Bechan
+2  A: 
preg_match('~^/[a-z]{2}(?:/|$)~', $_SERVER['REQUEST_URI']
serg