没有名称和问号的PHP Nginx Url参数

I've been trying to create a php api that accepts requests in the following formant:

POST localhost/HW3/api.php/register
GET localhost/HW3/api.php/users

This means that in my api.php file I have the following code:

<?php

$path = ltrim($_SERVER['REQUEST_URI'], '/');    // Trim leading slash(es)
$elements = explode('/', $path);                // Split path on slashes
print_r($elements);

?>

I want to check the last element of the array, in that case, I want to call one method for the register and another for the users.

I am not allowed to use any frameworks, just pure php. I am running Nginx and when I make a POST/GET request in the following form:

http://localhost/HW3/api.php

Everything is fine and I get:

Array
(
    [0] => HW3
    [1] => api.php
)

as a result which is fine. However, if I make a request like this:

http://localhost/HW3/api.php/register

I get a 404 error. Probably because Nginx thinks that api.php is a folder. Any ideas on how to fix that?