In jetty, $_SERVER['REQUEST_URI'] shows incorrect request_uri when index.php is used as a welcome file. request to / is transparently forwarded to /index.php by Jetty, and the request_uri in PHP is the forwarded uri ("/index.php") instead of the original request uri ("/")
JavaBridge is using the following code to obtain the request_uri in FastCGIServlet.java:
env.requestUri = (String) req.getAttribute("javax.servlet.include.request_uri");
if (env.requestUri == null) env.requestUri = req.getRequestURI();
In my Jetty environment, req.getAttribute("javax.servlet.include.request_uri") returns null, however, req.getAttribute("javax.servlet.forward.request_uri") will return the correct uri before forwarding. (i.e. "/test/" instead of "/test/index.php")
Both javax.servlet.include.request_uri and javax.servlet.forward.request_uri are defined in the Servlet spec. For include, in Servlet spec 8.3.1, it is stated that:
These attributes are accessible from the included servlet via the getAttribute method on the request object and their values must be equal to the request URI, context path, servlet path, path info, and query string of the included servlet, respectively. If the request is subsequently included, these attributes are replaced for that include.
For forward, in Servlet spec 8.4.2, it is stated that:
The values of these attributes must be equal to the return values of the HttpServletRequest methods getRequestURI, getContextPath, getServletPath, getPathInfo, getQueryString respectively, invoked on the request object passed to the first servlet object in the call chain that received the request from the client.
A simple solution is to replace javax.servlet.include.request_uri with javax.servlet.forward.request_uri as the latter one is said as the first servlet request uri, i.e. it won't use the forwarded uri. Or just check both attributes.
Regardless of what the Servlet spec said, Tomcat and Jetty are the two most popular open source servlet engine and I'll test the behavior in Tomcat and make sure we can get the correct request_uri in both servlet engines before submitting a patch.
also see the mail list message with the same title