title: NGINX rewrite root url with language suffix
body: <p>I am trying to add a simple rule to my NGINX configuration whereby the root url <code>www.example.com</code> is always rewritten with a language suffix <code>www.example.com/en/</code>. I have tried this:</p>
  
  <pre><code>server {
      listen 80;
      server_name www.example.com;
  
      location / {
          rewrite ^$ www.example.com/en/ permanent;
      }
  
      ...
  }
  </code></pre>
  
  <p>But no luck. Where am I going wrong? Also, is it possible to have a condition where NGINX checks if there is an<code>/en/</code> suffix and if not, adds one?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>So I was only one character away from what I wanted initially:</p>
  
  <pre><code>server {
      listen 80;
      server_name www.example.com;
  
      location / {
          # needed the / in between the anchor tags
          rewrite ^/$ www.example.com/en/ permanent;
      }
  
      ...
  }
  </code></pre>