Can someone help with a URL rewrite rule please


I would like to have users come to (example: They should see a wordpress page I would like the script on to be able to use the code (3928). No matter what the code provided in the URL is, the user will see the same page, /contact.

I am guessing I need a rewrite rule, and I am having a lot of trouble understanding how to do it. I’ve placed the code in the file /var/www/ I first tried:

location ~ / {
    rewrite ^/code/(.*)$ /contact?code=$1;

and then

location ~ / {
    try_files $uri $uri/ /contact?$args;

I’m a little confused – if anyone can point me in the right direction I’d be grateful.