一个字母的Nginx location regexp

一个字母的Nginx location regexp,nginx,Nginx,如何正确设置查询类型的位置和重写: 请求: site.com/a/?f=qwerty site.com/a?g=qwerty site.com/anyshorttext/?h=qwerty 改写为: /a/?f=qwerty /b/?g=qwerty /special/?h=qwerty 请求: site.com/a/?f=qwerty site.com/a?g=qwerty site.com/anyshorttext/?h=qwerty 改写为: /a/?f=qwer

如何正确设置查询类型的位置重写

请求:

site.com/a/?f=qwerty 
site.com/a?g=qwerty
site.com/anyshorttext/?h=qwerty 
改写为:

/a/?f=qwerty
/b/?g=qwerty
/special/?h=qwerty
请求:

site.com/a/?f=qwerty 
site.com/a?g=qwerty
site.com/anyshorttext/?h=qwerty 
改写为:

/a/?f=qwerty
/b/?g=qwerty
/special/?h=qwerty
请求:

site.com/a/?f=qwerty 
site.com/a?g=qwerty
site.com/anyshorttext/?h=qwerty 
改写为:

/a/?f=qwerty
/b/?g=qwerty
/special/?h=qwerty
我应用了这些解决方案:

server {
  location ~ /a/?(.*)$ {
    rewrite ^/([-\w]+) /a/?m=$1 break;
    index  index.php index.html index.htm;
    try_files $uri $uri/ =404;
    location ~ \.php$ {
      include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.2-fpm.sock;
    }
  }
  location ~* ^/[a-zA-Z0-9/_$/]+$ {
    rewrite ^/([-\w]+) /special/?h=$1 break;
    index  index.php index.html index.htm;
    try_files $uri $uri/ =404;
    location ~ \.php$ {
      include snippets/fastcgi-php.conf;
       fastcgi_pass unix:/run/php/php7.1-fpm.sock;
    }
  }
}