title: How to make Wordpress permalinks ignore custom url rewrite
body: <p>i'm currently working on a wordpress site that needs to have the option to be offered in french. i've found a way to make the theme work with the fr_FR po and mo files when i add a querystring variable <code>l</code>. i.e.</p>
  
  <p><code>site.tld</code> will yield the vanilla english site, while <code>site.tld/?l=fr</code> will activate the following code in my functions.php to serve the french translation:</p>
  
  <pre><code>&lt;?php
  // http://codex.wordpress.org/Plugin_API/Filter_Reference/locale
  add_filter( 'locale', 'set_my_locale' );
  function set_my_locale( $lang ) {
      if ("fr" == substr(strtolower(trim(strip_tags(stripslashes($_GET['l'])))), 0, 2)) {
          // set language to french
          return "fr_FR";
      } else {
          // return original locale
          return $lang;
      }
  }
  ?&gt;
  </code></pre>
  
  <p>this setup is already working. my question is: how do i rewrite the url so instead of <code>site.tld/?l=fr</code> i can just prepend the folder structure with <code>fr</code> i.e. <code>site.tld/fr/</code>?</p>
  
  <p>so like if there's a page <code>site.tld/portoflio/autumn/</code> in english, <code>site.tld/fr/portfolio/autumn/</code> will spit out the french one. i got this idea from the apple website, where the language is always prepended to the folder structure.</p>
  
  <p>i can already make this happen with an external redirect in htaccess:</p>
  
  <pre><code>RewriteBase /
  RewriteCond ^[a-z]{2}/
  RewriteRule ^([a-z]{2})/(.*)$ /$2?l=$1 [R,L]
  </code></pre>
  
  <p>this works, but once i remove the <code>R</code> flag it serves the french-translated 404 not found isntead. i'm guessing what i did is messing-up with wordpress' rewrite rules because i need to use pretty permalinks. right now i'm set to use <code>Month and name</code> (<code>/%year%/%monthnum%/%postname%/</code>) in the admin general options.</p>
  
  <p>my question is, how do i make wordpress ignore the <code>/fr/</code> part and still serve the correct page/post/etc?</p>
  
  <p>is this even possible? am i on the right track here? i need your help especially doing what's WISE and not just what's NICE. i tried this <a href="http://pmg.co/a-mostly-complete-guide-to-the-wordpress-rewrite-api" rel="nofollow">http://pmg.co/a-mostly-complete-guide-to-the-wordpress-rewrite-api</a> but for the life of me i can't make it work. :/</p>
  
  <hr>
  
  <p><strong>UPDATE</strong>: ok, so here's some progress taking cue from @relu below:</p>
  
  <p>i made sure my rules were canned from <code>.htaccess</code></p>
  
  <p>i then added the rules from @relu but in the following way, because Relu's always sent me to the same address without the <code>/fr</code>:</p>
  
  <pre><code>&lt;?
      // http://pmg.co/custom-wordpress-shortlinks
      add_action( 'init', 'pmgtut_add_rewrites' );
      function pmgtut_add_rewrites() {
          add_rewrite_rule( '^([a-z]{2})/?$', 'index.php?l=$matches[1]', 'top' );
          add_rewrite_rule( '^([a-z]{2})/(.*)$', 'index.php?l=$matches[1]&amp;q=$matches[2]', 'top' );
      }
      add_filter( 'query_vars', 'pmgtut_query_vars', 10, 1 );
      function pmgtut_query_vars( $vars ) {
          $vars[] = 'l';
          return $vars;
      }
  ?&gt;
  </code></pre>
  
  <p>now the <code>/fr</code> stays in the address bar, so that's a good thing, but two problems persist:</p>
  
  <ol>
  <li><p>wordpress is serving me the main index page. seems like it's not using the <code>&amp;q=$matches[2]</code> part of the rule; and</p></li>
  <li><p>the locale still doesn't get set properly. i checked if the variable <code>l</code> is getting fed, so i added <code>echo 'l: $l';</code> after <code>$l = get_query_var('l');</code> and interestingly i get two echoes: one <code>l:</code> and another <code>l: fr</code> right after that. is the <code>locale</code> filter being run twice? seems like the first time it doesn't see the value of the queryvar, and then there seems to be a second time that it outputs <code>l:</code> with <code>fr</code> already in there.. at the end of the day the locale still doesn't get changed.</p></li>
  </ol>
  
  <p>aaaah help.</p>
  
  <hr>
  
  <p><strong>FINAL UPDATE</strong>: in my last breath of frustration i searched again, and found this plugin qtranslate. does what i need. thanks y'all, esp to @relu's epic effort and stayin pow'r.</p>