Passing Nginx Rewrite To PHP

I’ve created the following Nginx Rewrite:

rewrite ^/([0-9A-Za-z]*)$ /index.php?redirect_reference=$1;

Then in my index.php I have:

<?php

        echo $redirect_reference . "rn";

There is no output for the value of $redirect_reference. I am unsure and need help.

I am setting up a sub-domain like redirect.example.com and wanting to use redirect.example.com/12345 so a minimum number of characters is used in sharing a link on social media posts.

For URLs such as redirect.example.com/12345 the number will be used to query the database for link 12345. Then I will query the database for the link 12345 represents and use the PHP header function to redirect to the requested web page.

For all others (such as fishing attempts) I want to setup a redirect to the home page IE www.example.com.