for an php application i need to rewrite all requests (for where is no file) to index.php

for a 404 handler i dont know, how i could execute the index.php

for a rewrite i have the Problem, that there is the index.php in the REQUEST_URI Variable.

for example, at the moment it will be rewritten to

but the REQUEST_URI should look like

but i dont get it, that the index.php will executet with it.

My code for the rewrite til now

arg_rewrite(ARG) ->
            Req = ARG#arg.req,
            case Req#http_request.path of %%dont know yet, how i get the values without an case call
            {abs_path, RealPath} ->
                case re:run(re:replace(RealPath,"/index\.php","",[{return,list}]),"^/(?:images|styles|scripts)/.*",[]) of
                nomatch ->
                    Req2 = Req#http_request{path = {abs_path, "/index.php" ++  re:replace(RealPath,"/index\.php","",[{return,list}])}};
                _Other ->
                    Req2 = Req#http_request{path = {abs_path, re:replace(RealPath,"/index\.php","",[{return,list}])}}
            %Req2 = Req#http_request{path = {abs_path, "/index.php"}},
            ARG2 = ARG#arg{req = Req2},           

how could i change the REQUEST_URI without strip the index.php from abs_path(what is i think the path, which file is delivered to the browser?)