title: nginx catchall subdomain not mapping to a specific map
body: <p>I have a bit of problem with Nginx.
  I want to use a wildcard subdomain that everythinghere.domain.com redirects to a specific map.</p>
  
  <p>This is my currect Nginx setting (I replaced the domainname with domain.com):</p>
  
  <pre><code>server_name  domain.com www.domain.com 1.domain.com workspace.domain.com *.domain.com;
  
      root   /var/www/domain.com/web/;
  
      if ($http_host = "1.domain.com") {
          rewrite ^(?!/(1|stats|error|\.well-known/acme-challenge))/(.*)$ /1/$2 last;
      }
      if ($http_host = "workspace.domain.com") {
          rewrite ^(?!/(1|stats|error|\.well-known/acme-challenge))/(.*)$ /1/$2 last;
      }
      if ($http_host = "*.domain.com") {
          rewrite ^(?!/(1|stats|error|\.well-known/acme-challenge))/(.*)$ /1/$2 redirect;
      }
  </code></pre>
  
  <p>With above 1.domain.com and workspace.domain.com redirects (maps) correctly to the map /1/. The wildcard seems to work, but it doesn't map to /1/ but only to the root map. </p>
  
  <p>So for example: 555.domain.com maps to root instead of /1/.</p>
  
  <p>I think the problem is in the last 'if' line with the *.</p>
  
  <p>Anyone a solution?</p>
  
  <p>Thanks in advance!</p>