title: Nginx - multiple/nested IF statements
body: <p>What i want to do:</p>
  
  <ul>
  <li>Check if request comes from Facebook</li>
  <li>Check if URL is like domain.com/2</li>
  <li>If above conditions are true - show content from /api/content/item/$1?social=1</li>
  <li>If above conditions are false - show "normal page"</li>
  </ul>
  
  <p>It is a single page app. Before my changes configuration looked like this (and it worked):</p>
  
  <pre><code>location / {
      root /home/eshlox/projects/XXX/project/project/assets/dist;
      try_files $uri $uri/ /index.html =404;
  }
  </code></pre>
  
  <p>I've tried to use if statements:</p>
  
  <pre><code>location / {
      set $social 1;
      if ($http_user_agent ~* "facebookexternalhit") {
          set $social UA; 
      }       
      if ($uri ~* "^/(\d+)$") {
          set $social "${social}URL";
      }       
      if ($social = UAURL) {
          rewrite ^/(\d+)$ /api/content/item/$1?social=1;
      }
  
      root /home/eshlox/projects/XXX/project/project/assets/dist;
      try_files $uri $uri/ /index.html =404;
  }
  </code></pre>
  
  <p>With this configuration everything works as i expected only if both conditions are true or false.
  If one of conditions is true and the second is false (or vice versa) then nginx always returns status 404.</p>
  
  <p>I have found "IfIsEvil" on nginx site, i've tried to use mapping (can i use mapping in this case?) but still i can't resolve this problem.</p>
  
  <p>Any ideas?</p>
  
  <p>Best regards.</p>