Rewriting nginx's try_files

I am trying to convert a very simple rewrite from a previous nginx version to the current one looking like below:

location / {
   if ( !-f $request_filename ) {
     rewrite ^/([a-z]*)$ /index.php?action=$1;
     rewrite ^/([a-z]*)/(.*)$ /index.php?action=$1&item=$2;
   }
}

This is how far I have gotten. The index page shows up, but any page that should be rewritten like above, instead throws 404's:

server {

    listen 80 default;
    root /var/www;
    index index.php;
    server_name _;

    location / {
        try_files $uri $uri/ /index.php?action=$uri&item=$args;
    }

    location ~ \.php$ {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        include fastcgi_params;
    }
}

What am I doing wrong here?


This should work:

location / { 
    try_files $uri $uri/ @rules; 
} 

location @rules { 
    rewrite ^/([a-z]*)$ /index.php?action=$1; 
    rewrite ^/([a-z]*)/(.*)$ /index.php?action=$1&item=$2; 
}

location /index.php { 
    fastcgi_pass 127.0.0.1:9000; 
    include fastcgi_params; 
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
}