title: .htaccess rule for multilingual site
body: <p>I'm redesigning the URL of a PHP multilingual site (en|es|de|fr|ru). The URL's of the site are this way:</p>
  
  <pre><code>www.mysite.com/page
  www.mysite.com/page/subpage1
  www.mysite.com/page/subpage1/subpage2
  www.mysite.com/page/subpage1/subpage2/subpage3
  </code></pre>
  
  <p>Up to four levels of subdirectories (products, subproducts, etc.). The language is passed as a GET parameter:</p>
  
  <pre><code>www.mysite.com/page?lang=es
  </code></pre>
  
  <p>or</p>
  
  <pre><code>www.mysite.com/page/subpage1/subpage2?lang=de
  </code></pre>
  
  <p>The current .htaccess is something like this:</p>
  
  <pre><code>Options +FollowSymlinks +MultiViews -Indexes
  RewriteEngine on
  
  RewriteBase /
  
  # Redirect all versions of homepage to www.mysite.com
  RewriteCond %{REQUEST_URI} ^/index\.html$
  RewriteRule ^index.html$ http://www.mysite.com/ [R=301,L]
  
  # Redirect non-www to www traffic
  RewriteCond %{HTTP_HOST} !^(www\.mysite\.com)?$
  RewriteRule (.*) http://www.mysite.com/$1 [R=301,L]
  
  RewriteCond %{SCRIPT_FILENAME} !-d
  RewriteCond %{SCRIPT_FILENAME} !-f
  
  #Remove php extension
  RewriteCond %{REQUEST_URI} ^(.*).php$
  RewriteRule ^(.*)$ %1 [R=301,QSA] 
  
  #Here I have a lot of 301 redirections, I ommit them for this example
  
  # First level redirections
  RewriteRule ^([0-9a-zA-Z\-\_]+)$ view?page=$1 [L,QSA]
  
  # Second level redirections
  #RewriteRule ^(page1|page2|page3)\/([0-9a-zA-Z\-\+\_\,\.\(\)]+)$ view?page=$1&amp;subpage1=$2 [L,QSA]
  
  # Third level redirections
  RewriteRule ^([0-9a-zA-Z\-\_]+)\/([0-9a-zA-Z\-\+\_\,\.\(\)]+)\/([0-9a-zA-Z\-\_]+)$ view?page=$1&amp;subpage1=$2&amp;subpage2=$3 [L,QSA]
  
  # Fourth level redirections
  RewriteRule ^([0-9a-zA-Z\-\_]+)\/([0-9a-zA-Z\-]+)\/([0-9a-zA-Z\-]+)\/([0-9a-zA-Z\-]+)$ view?page=$1&amp;subpage1=$2&amp;subpage2=$3&amp;subpage3=$4 [L,QSA]
  </code></pre>
  
  <p>Now I want to redirect the whole site to a URL with a prepended language subdirectory if there is no language parameter in the URL (GET), like this (default english language):</p>
  
  <pre><code>www.mysite.com/page -&gt; www.mysite.com/en/page
  www.mysite.com/page/subpage1 -&gt; www.mysite.com/en/page/subpage1
  </code></pre>
  
  <p>and if the GET parameter is passed in the URL, I want to redirect to the correct URL:</p>
  
  <pre><code>www.mysite.com/page?lang=es -&gt; www.mysite.com/es/page
  www.mysite.com/page/subpage1?lang=es -&gt; www.mysite.com/es/page/subpage1
  </code></pre>
  
  <p>I've reviewed other similar questions but all of them are based in a 301 redirect with last parameter ([R=301,L]), and I'm afraid that the Last is not valid for me.</p>
  
  <p>I have a few questions:</p>
  
  <ol>
  <li>Is there a way to make the .htaccess easier, not having a rule for each level?</li>
  <li>How can I redirect my whole site to www.mysite.com/en if no lang GET parameter is passed in the URL?</li>
  <li>How can I redirect to the correct localized site according to the lang GET parameter (www.mysite.com/page?lang=es -> redirect to www.mysite.com/es/page)</li>
  </ol>
  
  <p>Thanks in advance</p>