title: NGINX with 2 conditions which need a rewrite
body: <p>I have 2 different sites
  www.example1.com
  www.example2.com</p>
  
  <p>each of them have a folder e.g. 
  <a href="https://www.example1.com/store/test/en/test/ANYCATEGORY/ANDCATEGORY/OPTIONALCATEGORY/PROGRAMNAME/p/100002020" rel="nofollow noreferrer">https://www.example1.com/store/test/en/test/ANYCATEGORY/ANDCATEGORY/OPTIONALCATEGORY/PROGRAMNAME/p/100002020</a>
  <a href="https://www.example2.com/store/test/en/test/ANYCATEGORY/ANDCATEGORY/OPTIONALCATEGORY/PROGRAMNAME/p/100002020" rel="nofollow noreferrer">https://www.example2.com/store/test/en/test/ANYCATEGORY/ANDCATEGORY/OPTIONALCATEGORY/PROGRAMNAME/p/100002020</a></p>
  
  <p>The idea is to apply an nginx rule which matches 2 conditions, the host and uri if there is no .html at the end</p>
  
  <p>This is what i have for appending .html if there is no .html currently present </p>
  
  <pre><code>  location ~ ^(?=.*\/p\/)(?!.*\.html$).+$ {
    try_files $uri $uri/ @rewrite;
    }
    location @rewrite {
    rewrite ^(.+)$ $1.html permanent;
    }
  </code></pre>
  
  <p>I want to apply the above condition only to www.example2.com and NOT www.example1.com</p>
  
  <p>how is this possible? i have tried a few things but location only seems to deal with the URI rather than $host/$uri?</p>
  
  <p>I have tried below:</p>
  
  <pre><code>  location ~ ^https://(?![example1])(?=.*\/p\/)(?!.*\.html$).+$ 
  </code></pre>
  
  <p>but that does not work.</p>
  
  <p>Also tried this with no luck</p>
  
  <pre><code>  set $tmp '';
    if ($http_origin ~ "^https?://(?!(oasis-)).*") {
     set $tmp 1;
    }
    if ($request_uri ~ ^(?=.*\/p\/)(?!.*\.html$).+$) {
     set $tmp "${tmp}1";
    }
    if ($tmp = 11) {
     rewrite ^(.+)$ $1.html permanent;
    }
  
  </code></pre>