rewrite правила Gallery2 на Nginx

location /v/
{
    if ($request_uri !~ /main.php)
    {
        rewrite ^/v/(.*)$ /main.php?g2_view=core.ShowItem&g2_path=$1 
last;
    }
}

location /d/
{

    if ($request_uri !~ /main.php)
    {

rewrite /d/(\d+)-(\d+)/([^/?]+)/main.php?g2_view=core.DownloadItem&g2_itemId=$1&g2_serialNumber=$2&g2_fileName=$3
last;
    }

}