As already mentioned, you can't read the POST body using mod_rewrite. However, you can read the Cookie
header (using the HTTP_COOKIE
server variable) and any other custom HTTP request header.
If the information you require is available in a custom header then it's probably easier/safer to read that since the HTTP_COOKIE
contains all the cookie name/value pairs sent from the client so you must be particular in extracting the required information.
If the required information is always contained in the X-Prefix
HTTP request header then you can internally rewrite the request with a single mod_rewrite directive:
RewriteRule ^/?(myApp)$ /%{HTTP:X-Prefix}/$1 [L]
The $1
backreference simply saves having to repeat the myApp
string in the substitution from the requested URL-path.
If you want to first check that the HTTP request header is set before rewriting then you can use an additional condition:
RewriteCond %{HTTP:X-Prefix} (.+)
RewriteRule ^/?(myApp)$ /%1/$1 [L]
In the second rule block, the request is only rewritten if the X-Prefix
header is set and has a value. This is captured using the %1
backreference, rather than referring to the custom HTTP directly in the substitution string (which we could do, but just saves repetition).