Faced a problem that collectively solved almost a day.
Briefly: there is a website, all pages / templates of which are processed and delivered through a single index.php, and also for organizing CNC (friendly urls) htaccess is used with a rather considerable list of various RewriteRule rules.
And everything would be fine, but it took to solve one problem to know, and what address the client is requesting. That is, in fact, the php script is known-not-knows what the user entered in the address bar, since the request he receives is already htaccess, which causes the needed script.
')
The result was that the real URL of the page could only be taken on the client side via javascript.
Printing out all kinds of superglobal arrays of the type $ _SERVER showed that the real address is not contained in any of the variables.
It became clear that the answer should obviously be sought only in the htaccess file.
The first option was to try to use the ability to set and pass environment variables to scripts, so something like this was written at the very beginning of htaccess:
SetEnvIf Request_URI "(. *)" My = $ 1
SetEnvIf REDIRECT_my (. +) My = $ 1
Passenv my
Indeed, the $ my variable begins to be visible in the $ _SERVER array, but the value was still the same as after processing by further htaccess rules.
I suppose that this will work in some cases, however, in our case, it seems that there was a multiple pass of the htaccess file (for some of the tasks, we also use mod_proxy).
Then the idea came to transmit at each reraite the URL from which the rewrite occurs, for example
RewriteRule ^ photo / ([0-9] +). Html $ / rubricator / photo.html?%{QUERY_STRING} & id =$1 & url = $ 0 [P, L]
As a result, in any script, the $ _SERVER [“url”] variable becomes available to us, which contains the desired appendage of the URL (except for the understandable case of the domain itself).
Long search on the web did not give a solution, so I decided to share my experience with the community.