How to get base URL of index file in PHP after htaccess redirect that doesn’t change the URL

I have this in my htaccess:

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

and I have a PHP script that is redirecting to two directories /game/ or block/ I want to use curl to open files in one of the directories.

This is my code for getting the URL:

function is_https() {
    // apache
    if (isset($_SERVER['HTTPS'])) {
        return true;
    }
    // heroku
    if (isset($_SERVER['HTTP_X_FORWARDED_PORT']) && isset($_SERVER['HTTP_X_FORWARDED_PROTO'])) {
        return $_SERVER['HTTP_X_FORWARDED_PORT'] == 443 || $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https';
    }
    return false;
}

function get_self() {
    return 'http' . (is_https() ? 's' : '') . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
}

function main() {

    $addresses = json_decode(file_get_contents('ip.json'));
    $url = get_self() . (in_array($_SERVER['REMOTE_ADDR'], $addresses) ? "/block/" : "/game/");
    $url .= $_GET['q'];
    
    echo $url;
}

if (isset($_GET['q'])) {
    main();
}

The problem is that when I access the file locally for testing when I try to access:

http://localhost/~kuba/jcubic/support/order/app/index.js

It got this URL:

http://localhost/~kuba/jcubic/support/order/app/index.js/game/index.js

how can I get the URL of the index.php the path where the .htaccess file is located?

I one this to work as the root directory https://example.com/ the same as in any directory.