I presently possess a pretty easy modrewrite file that maps web addresses to various php pages with possible GET variables:

RewriteRule ^grant$ about.php?p=4 [L]
RewriteRule ^contact-people-([A-za-z0-9-]+)$ about.php?p=5&to=$1 [L]
RewriteRule ^([a-z0-9-]+)-media$ media-gallery-element.php?prettyid=$1 [L]
#etc .... it goes on for perhaps 200 or so entries

I wish to possess a global language variable that's within the url and I am wondering the way i can smartly adjust my modrewrite file additional. I possibly could get it done by doubling my records and merely increase the rules so that the first above will get transformed to:

RewriteRule ^grant$ about.php?p=4&lan=en [L]
RewriteRule ^([a-z]+)/grant$ about.php?p=4&lan=$1 [L]

The very first row is likewise and would default to british (en) and so the second row handles other language codes, es, fr, p, etc. And So I could get it done by doing this, however it appears like there's an easy method to get this done without doubling my records. Essentially, I wish to take All my demands, search for a ([a-z]+)/ at the outset of the request uri, after which tack that to the request like a GET variable, lan.

How do you do that smartly?

This can be done easily by setting an environment variable. Something similar to this will have the desired effect:

# set default environmental variable for language
RewriteRule .* - [E=language:en]

# if two characters and slash lead, then
RewriteCond %{REQUEST_URI} ^/([a-z]{2})/(.*)$     

# overwrite default environmental variable
RewriteRule .* - [E=language:%1] 

# other rules
RewriteRule ^grant$ about.php?p=4&lan=%{ENV:language} [L]

You may also access the environment variable directly in PHP, by which situation you can skip including it within the rewrite rules:

echo getenv('language');
echo $_SERVER['language'];
echo $_SERVER['REDIRECT_language'];