title: Htaccess - redirect old site with variables to new subdomain
body: <p>So, basically, the old site is whole made in flash and I want to switch to html version, assign it to subdomain, and keep all links working. An example url for the flash looks like this: </p>
  
  <p><em><a href="http://site.com/dir/?language=french#/gallery/folder1/image1.jpg" rel="nofollow">http://site.com/dir/?language=french#/gallery/folder1/image1.jpg</a></em></p>
  
  <p>From the url above, I need to get pretty one, like this:</p>
  
  <p><em><a href="http://dir.site.com/FR/gallery/folder1/image1.jpg" rel="nofollow">http://dir.site.com/FR/gallery/folder1/image1.jpg</a></em></p>
  
  <p>Of course, if the language variable is not specified I would like to assign a default lang "EN" to the url, so I can make the language controller switch (there will be only two languages - french/FR and english/EN).</p>
  
  <p>My current htaccess file (<a href="http://site.com/dir/.htaccess" rel="nofollow">http://site.com/dir/.htaccess</a>) looks like this:</p>
  
  <pre><code>RewriteCond %{REQUEST_URI} ^/dir
  RewriteRule ^(.*)$ http://dir.site.com/$1 [R=301,L,P]
  
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . index.php
  </code></pre>
  
  <p>Now I need only convert the language variable like in the example above, but when I'm trying to set another rule in htaccess, my site gets redirect loop error :/</p>
  
  <p>As for the hash (#) in the url - I made JS in the index.php file (which is my first controller), so the only thing left is the language...</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      if (location.href.indexOf("#") &gt; -1) {
         location.assign(location.href.replace(/\/?#/, ""));
      }
  &lt;/script&gt;
  </code></pre>