title: Rewrite rules in Wordpress from url parameter and show custom content
body: <p>I am trying to rewrite urls in Wordpress in the following way:</p>
  
  <p>Requested urls:</p>
  
  <p><a href="http://example.com/page" rel="nofollow">http://example.com/page</a></p>
  
  <p><a href="http://example.com/page/?lang=en-GB" rel="nofollow">http://example.com/page/?lang=en-GB</a></p>
  
  <p><a href="http://example.com/page/?lang=en-WLS" rel="nofollow">http://example.com/page/?lang=en-WLS</a></p>
  
  <p><a href="http://example.com/page/?lang=en-SCT" rel="nofollow">http://example.com/page/?lang=en-SCT</a></p>
  
  <p>Rewritten to:</p>
  
  <p><a href="http://example.com/page" rel="nofollow">http://example.com/page</a></p>
  
  <p><a href="http://example.com/nireland/page/" rel="nofollow">http://example.com/nireland/page/</a></p>
  
  <p><a href="http://example.com/wales/page/" rel="nofollow">http://example.com/wales/page/</a></p>
  
  <p><a href="http://example.com/scotland/page/" rel="nofollow">http://example.com/scotland/page/</a></p>
  
  <p>I then ideally need to access which country has been requested so that I can display the appropriate content for that country.</p>
  
  <p>Each of these urls should point to the same page.  Each page has page meta for the different country content.</p>
  
  <p>This is my code so far, but I am not sure how to proceed</p>
  
  <pre><code>function language_rewrite()
  {
      add_rewrite_rule(
          '/([^/]+)?$/i',
          'index.php?lang=matches[1]',
          'top'
      );
  
      add_rewrite_tag('%lang%','([^/]*)');
  }
  add_action('init', 'language_rewrite');
  
  function vars($vars)
  {
      $vars[] = 'lang';
      return $vars;
  }
  add_filter('query_vars', 'vars');
  </code></pre>
  
  <p>Can someone point me in the right direction?</p>
  
  <p>Many thanks, G.</p>
  
  <p><strong>EDIT:</strong> </p>
  
  <pre><code>add_rewrite_rule('^scotland/?([^/]*)', 'index.php?lang=en-SCT&amp;pagename=$matches[1]', 'top');
  add_rewrite_tag('%lang%','([^/]*)');
  </code></pre>
  
  <p><strong>EDIT2:</strong></p>
  
  <pre><code>add_rewrite_rule('^scotland/?([^/]*)/?([^/]*)/?([^/]*)/?([^/]*)/?([^/]*)', 'index.php?lang=en-SCT&amp;pagename=$matches[1]/$matches[2]/$matches[3]/$matches[4]/$matches[5]', 'top');
  </code></pre>