Apache dynamic ProxyPass with Port via URL

I would like to pass any traffic coming to Apache by a specific URL to a specific port via ProxyPass. This is the idea which works, but I would like to set this up dynamically based on the given port in the URL - plus everything that incomes after the port

<VirtualHost *:80>  
    <Location "/6000">
            ProxyPass "http://localhost:6000/"
            ProxyPassReverse "http://localhost:6000/"

    <Location "/7000">
            ProxyPass "http://localhost:7000/"
            ProxyPassReverse "http://localhost:7000/"

So for example if I open up http://myapache/8000/test/.... the traffic should go to http://localhost:8000/test/.... and so on.

I have tried some attempts with %{QUERY_STRING} but Apache throws some syntax errors while starting it up.

Edit: After searching for hours I finally found a similar question


However I am not quite sure on how to implement this to my config (I get HTTP 502 Proxy Error)

.htaccess .net .net-core 2d 3d 3d-printing abstract-syntax-tree actions-on-google actionscript-3 activemq acumatica adobe-xd aframe ag-grid air airflow ajax akka alexa algorithm alignment allure amadeus amazon-cognito amazon-deequ amazon-dynamodb amazon-ec2 amazon-redshift amazon-s3 amazon-sqs