What is the best way to parse the link passed by mod_rewrite and received by the script? I do not have problems with parsing links like:

 domainname/controller/action?parameter 

if the script is in the domain root and mod_rewrite redirects to domainname/index.php But if the same script is in some directory, for example domainname/script/index.php then the value of the $_SERVER['REQUEST_URI'] variable becomes "/script/controller/action?parameter" and the processing function takes the first value of" script "for the controller .

Tell me, please, some way, preferably without using regular expressions, to correctly parse the link, no matter which directory the script is in, in the root or subdirectory?

In a different way: how can I trim $_SERVER['REQUEST_URI'] so that the script itself determines in which directory it is located, matches it, and starts parsing with the corresponding slash?

I understand that you can manually specify the location of the script so that it knows exactly how to parse $_SERVER['REQUEST_URI'] , but the task is to make a universal script that works correctly, regardless of which directory or subdirectory of the server it is in.

1 answer 1

It turned out that for the task, it is enough to parse the variable QUERY_STRING , and not REQUEST_URI . It passes just the necessary part of the URI.