Checking if language is set in url with regex

Posted by Saif Bechan on Stack Overflow See other posts from Stack Overflow or by Saif Bechan
Published on 2010-05-13T20:41:29Z Indexed on 2010/05/13 20:44 UTC
Read the original article Hit count: 346

Filed under:
|

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?

© Stack Overflow or respective owner

Related posts about php

Related posts about regex