Nginx wordpress url重写,另有规则

I'm new to nginx and I'm configuring my server block. Currently everything works fine but now I'm trying to move my wordpress website that was on an Apache server. On my website I had a rewriting rule that allowed me to access a php page without specifying the .php extension. I had also the wordpress permalink rewriting rule.

Now on nginx, I managed to make them work but only separately:

location / { # Accessing php script without specifying the extension try_files $uri $uri/ $uri.html $uri.php?$query_string; }

...and...

location / { # Wordpress permalinks try_files $uri $uri/ /index.php?q=$uri&$args; }

What I would want to do, is making this two rules work together. I have no idea how to do it and I didn't find anything that corresponded to what I wanted.

Thanks very much !

If I understand your use case correctly, you should be able to combine the two into one location block like this:

location / {
  try_files $uri $uri/ $uri.html $uri.php /index.php?q=$uri&$args;
}

You'll still need a separate location block after that to process PHP. Something like:

location ~ \.php$ {
  #match actual filename with extension or file not found
  try_files $uri =404;

  #... or replace next lines with your preferred PHP processing config
  include fastcgi_params;
  fastcgi_pass unix:/var/run/php5-fpm.sock;
}

Of course, this is not the complete configuration but hopefully helps with this aspect.

I'm sure the solution you wrote me works well but I can't configure my server well. The problem is that php pages gets downloaded when the extension is not set. Here is my configuration, thanks for your kindness to look at it:

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    root /var/www/site.net/html;

    index index.html index.htm index.php;

    server_name site.net www.site.net;

    location / {
        try_files $uri $uri/ $uri.html $uri.php /index.php?q=$uri&$args;
    }

    # PHP CONFIGURATION

    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        include fastcgi_params;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include fastcgi.conf;
    }
}

(sorry for replying to the post, the code was to long to fit in a comment...)