title: Nginx rewrite in subfolder (404)
body: <p>I has a site host on a <strong>NGINX</strong> server which used to work fine to remove <code>index.php</code> in nginx site config using <code>try_files</code>.</p>
  
  <p>But now I am going to add a blog on it, where the URL will be <code>www.foo.com/blog</code>, I can access the blog and use <code>index.php?p=</code>. </p>
  
  <p>But, once I use <em>pretty</em> permalink with Nginx Helper, <code>www.foo.com/blog/2013/07/bar</code>, I get <code>404</code>. </p>
  
  <pre><code>server {
    # don't forget to tell on which port this server listens
    listen 80;
  
    # listen on the www host
    server_name foo.com;
  
    # and redirect to the non-www host (declared below)
    return 301 $scheme://www.ultra-case.com$request_uri;
  }
  
  server {
    # listen 80 default_server deferred; # for Linux
    # listen 80 default_server accept_filter=httpready; # for FreeBSD
    listen 80;
  
    # The host name to respond to
    server_name www.foo.com;
  
    # Path for static files
    root /web/foo.com
  
    #index file
    index index.php;
  
    #Specify a charset
    charset utf-8;
  
    # Custom 404 page
    error_page 404 /404.html;
  
    # Uri Rewrite
  
    location /blog {
      index index.php;
      try_files $uri $uri/ /blog/index.php?$args;
    }
  
    location / {
      autoindex on;
      # This is cool because no php is touched for static content.
      # include tihe "?$args" part so non-default permalinks doesn't break when using query string
      try_files $uri $uri/ /index.php?$args;
    }
    location ~ \.php$ {
      #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
      include fastcgi.conf;
      fastcgi_intercept_errors on;
      fastcgi_pass 127.0.0.1:9000;
      fastcgi_index index.php;
    }
  
    # Include the component config parts for h5bp
    include conf/h5bp.conf;
  }
  </code></pre>