title: Nginx Joomla Internationalization URL rewriting
body: <p>I'm using Joomla in combination with Nginx, and I'm currently trying to achieve some URL rewriting for a website that has several langages supported (italian, french, chinese, and deutch)  </p>
  
  <p>The urls have the country code after the domain name, like so :<br>
      <code>http://www.example.com/fr/test/test.html</code><br>
      or<br>
      <code>http://www.example.com/de/test/test.html</code>  </p>
  
  <p>I'm looking to rewrite the urls so the country code is part of the subdomain :<br>
      so<br>
      <code>http://www.example.com/fr/test/test.html</code><br>
      becomes<br>
      <code>http://fr.example.com/test/test.html</code>  </p>
  
  <p>Is there a way to achieve this with Nginx or should I look into a third party extension for Joomla (not my favorite choice).  </p>
  
  <p>Thanks !!  </p>
  
  <p><strong>Update :</strong><br>
  I wasn't clear enough : I wanted the redirection from the rewrited URL to be transparent. Here is what I came up with, thanks to VBart help :</p>
  
  <pre><code>server {  
    server_name ~^(?&lt;lang&gt;.+)\.example\.com$;  
    location / {  
      rewrite /(.*)$ /$lang/$1 break;  
      proxy_pass http://www.example.com;  
      proxy_redirect http://www.example.com http://$lang.example.com/$request_uri;  
    }  
  }  
  </code></pre>
  
  <p>Now, is there a way for Nginx to modify links on the fly in the served content ? ie: I want all the link in the generated page to look like <code>http://fr...</code> instead of <code>http://.../fr/...</code> ?</p>