title: Htaccess 301 redirect with dynamic URLs
body: <p>I need to redirect my dynamic URLs with parameters to subfolder URLs.
  The source URL can vary in length/levels.</p>
  
  <p>An example would be:</p>
  
  <p><strong>Source:</strong></p>
  
  <pre><code>http://www.example.com/dir/?lang=en
  </code></pre>
  
  <p><strong>Desired:</strong></p>
  
  <pre><code>http://www.example.com/dir/en
  </code></pre>
  
  <p>and another would be:</p>
  
  <p><strong>Source:</strong></p>
  
  <pre><code>http://www.example.com/dir/subdir/?lang=en
  </code></pre>
  
  <p><strong>Desired:</strong></p>
  
  <pre><code>http://www.example.com/dir/subdir/en
  </code></pre>
  
  <p>I'm using WordPress, so there is some existing code in my <code>.htaccess</code>, which the redirect in question, needs to work with. My existing <code>.htaccess</code> looks like this:</p>
  
  <pre><code>RewriteEngine On
  RewriteBase /
  
  RewriteRule ^index\.php$ - [L]
  
  RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
  
  RewriteCond %{REQUEST_FILENAME} -f [OR]
  RewriteCond %{REQUEST_FILENAME} -d
  RewriteRule ^ - [L]
  
  RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L] 
  RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
  RewriteRule . index.php [L]
  </code></pre>
  
  <p>I tried searching the entire web, however, no solution/answer seems to fit this particular case.
  Any experts who can help?</p>