title: nginx how to redirect to wordpress folder if url contains specific word
body: <p>First of all my domain root is configured to serve an Angular webpage using a reverse proxy that redirects to local ip/port, that's working like a charm. The problem arrives now when I want to override root rule if url contains <code>/blog</code> which I want to redirect to a wordpress folder. At the moment and with this config I can reach wordpress but just specific urls like <code>example.com/blog/wp-admin/index.php</code>, but if i access <code>example.com/blog</code>is still going to angular app. I've configured my nginx as follows(I have to say is my first time configuring a webserver):</p>
  
  <pre><code>server {
      listen [::]:443 ssl http2;
      listen 443 ssl http2;
      server_name example.com www.example.com;
  
      client_max_body_size 100M;
      root /var/www;
      index index.php index.html index.htm index.nginx-debian.html;
      autoindex off;
  
      location ~ /blog(.*)+/(.*)$ {
          try_files $uri $uri/ /blog/index.php?$args /blog/index.php?q=$uri&amp;$args;
          location ~ \.php$ {
              include snippets/fastcgi-php.conf;
              fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
              fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
              include fastcgi_params;
          }
     }
  
      location / {
          proxy_pass http://127.0.0.1:4000;
          proxy_set_header Host $http_host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-NginX-Proxy true; proxy_redirect off;
          http2_push /var/www/example_frontend/dist/example-frontend/favicon.ico;
          http2_push /var/www/example_frontend/dist/example-frontend/manifest.json;
      }
  
      location /robots.txt {
          alias /var/www/example_frontend/robots.txt;
      }
  
      location /sitemap.xml {
          alias /var/www/example_frontend/sitemap.xml;
      }
  
      ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
      ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot
  }
  
  
  server {
      if ($host = www.example.com) {
          return 301 https://$host$request_uri;
      } # managed by Certbot
  
  
      if ($host = example.com) {
          return 301 https://$host$request_uri;
      } # managed by Certbot
  
  
      listen 80;
      server_name example.com www.example.com;
      return 404; # managed by Certbot
  }
  </code></pre>
  
  <p>It's working perfectly if I stop my angular app, so I think I need to trigger the /blog location in first place but I tried in all possible forms with no result. Does someone see what's wrong? I thought first rule is triggered first but seems not.</p>
  
  <p>Thanks in advance.</p>
  
  <p>I can append any other config file if required ;)</p>