title: URL rewrite in ASP.net for multi language
body: <p>With the example URL:</p>
  
  <pre><code>www.domain.com/contact-us
  </code></pre>
  
  <p>Which renders in <code>English</code>.  There are a set of other languages this website supports:</p>
  
  <pre><code>www.domain.com/es/contact-us
  www.domain.com/jp/contact-us  
  www.domain.com/de/contact-us
  www.domain.com/pt/contact-us
  </code></pre>
  
  <p>Here is the re-write rule for English (default language)</p>
  
  <pre><code>&lt;rewrite url="^/contact-us(\?(.+))?$" to="~/Pages/Contact.aspx$1" processing="stop"/&gt;
  </code></pre>
  
  <p>How would I modify this/add a new rule to re-write:</p>
  
  <pre><code>www.domain.com/jp/contact-us  
  </code></pre>
  
  <p>To:</p>
  
  <pre><code>~/Pages/Contact.aspx?language=jp
  </code></pre>
  
  <p>Preferably without having to write a new rule, for every language for every content page!</p>
  
  <p>To complicate things, it needs to match IETF language tags.  These are varied enough that it looks like a regex to match them would be a difficult route:
  <a href="https://en.wikipedia.org/wiki/IETF_language_tag" rel="noreferrer">https://en.wikipedia.org/wiki/IETF_language_tag</a></p>
  
  <p>Ideally I need to get the list of languages from the database, and match the language tag field on the fly.  But I'm not sure how to do this as I've only ever written static rules.</p>