PHP website not working as expected in NGINX but working in Apache

Hi I just created a link shortening app. But when I try to redirect a shorten link to the full URL which is shared on Facebook it is not working as expected. for example : https://bowa.me/c8443 this link is working fine but if i share the link in Facebook and and the link will be like this https://bowa.me/c8443?fbclid=IwAR0Zm8bGRgrbpQTUX_aVXxTMNFq6-MlRFe0j8e_7wm4anbWmvArPlyDaAHI This link is not redirecting

nginx config

location / {
            try_files $uri $uri/ /index.html /index.php;

    }

    location ~ \.php$ {
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
         }

        location ~ /\.ht {
            deny all;
      }

    if (!-e $request_filename) {
            rewrite ^/admin/(.*)?$ /admin/index.php?a=$1 break;
            rewrite ^/(.*)$ /index.php?a=$1 last;
            break;
    }

Solution 1:

In nginx, things should be done by following nginx best practices, not trying to convert Apache2 practices to nginx. That is a recipe for all kinds of problems.

You should try the following approach:

# block for processing PHP files
location ~ \.php$ {
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
}

location ~ /\.ht {
    deny all;
}

# Capture part after admin to variable and use in try_files
location ~ ^/admin/(.*)$ {
    try_files $uri $uri/ /admin/index.php?a=$1;
}

# Default location, capture URI part and use as argument
location ~ ^/(.*)$ {
    try_files $uri $uri/ /index.php?a=$1;
}

The order is important, nginx uses the first regular expression match from location blocks it finds.