Nginx Rewrite with a question mark

nginxquerystringredirectrewriteWordpress

I am trying to force Nginx to redirect/rewrite one URL that uses a query string /?cat=20 to /category/lighttpd/. Here is what I tried, which is not working:

location ~ /\?cat=20 {
    rewrite ^ http://kevinworthington.com/category/lighttpd/? permanent;
}

I first tried the first line as:

location ~ /?cat=20 {

but that didn't work for me either.

This is using WordPress as the CMS, if that makes any difference.

Your help or tips are appreciated. Thanks.

Best Answer

Just an example ...

location / {
    if ($arg_cat = "20") {
        return 301 http://kevinworthington.com/category/lighttpd/?;
    }
    # blablabla
}