Checking if language is set in url with regex
- by Saif Bechan
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?