Search code examples
phpapachereverse-proxymod-proxy

Apache mod_proxy obtain origin uri with simple proxy


Currently I use mod_proxy to serve a page on all subpaths (cause its a single page application which handles the content depending on the request uri.

RewriteRule ^/(.*)$ %{REQUEST_SCHEME}://%{HTTP_HOST}/ [P,L]

This works for the javascript part. The browser url stays for example at /user/1 but the index.php from the root / is served. The spa serves the proper content but now I need to know the requested uri also in php.

$_SERVER["REQUEST_URI"]

contains now / but I need to get somehow the origin requested uri. I tried to an additional requestheader:

SetEnvIf Request_URI "^(.*)$" REQUEST_URI=$1
RequestHeader set X-Request-Uri "%{REQUEST_URI}e"

but the additional request header only contains the rewritten uri.

is there any easy way to pass the origin request uri? There are no proxypass or proxypassreverse configurated. Or is there another way to serve the index.php on all subpaths and is proxing the wrong approach?


Solution

  • Ok I fixed it with passing it via query parameter:

    RewriteRule ^/(.*)$ %{REQUEST_SCHEME}://%{HTTP_HOST}/?origUrl=$0 [E=ORIG_URI:/$0,P,L,QSA]
    

    And on the php part I read the parameter:

    parse_str($_SERVER['QUERY_STRING'], $queryParams);
    

    and use it via:

    $queryParams['origUrl']