Problem/Motivation
We have request_uri, which abstracts $_SERVER['REQUEST_URI']:
/**
* Returns the equivalent of Apache's $_SERVER['REQUEST_URI'] variable.
*
* Because $_SERVER['REQUEST_URI'] is only available on Apache, we generate an
* equivalent using other environment variables.
*/
function request_uri() {
...
But in several places this is not used (e.g. request_path).
Proposed resolution
Use request_uri() consistently.
Remaining tasks
Patch, test, comit.
User interface changes
None.
API changes
None.
Data model changes
None.
Original summary
API page: https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/requ...
Enter a descriptive title (above) relating to function request_uri, then describe the problem you have found:
The documentation states that: "Because $_SERVER['REQUEST_URI'] is only available on Apache, we generate an equivalent using other environment variables.", but this is not accurate. Nginx also defines this variable.
The problem that I've encountered is that clean URLs are not being resolved correctly out-of-the-box on my Nginx setup because REQUEST_URI does not contain the front controller. I suspect that Apache includes the front controller in REQUEST_URI, whereas Nginx does not.
Example Request: http://www.site.com/registration
Apache defines REQUEST_URI as: /index.php/registration
Nginx defines REQUEST_URI as: /registration
I may be wrong about this, but the logic in the bootstrap.php request_path() leads me to this conclusion. It specifically uses basepath() to determine if the request is being made for the Home page with a request URI of /index.php and this ends up clearing the request $path variable, so all clean URIs on my site end up displaying the Home page.
In my Nginx environment, a request for www.site.com/registration ends up $path being defined as an empty string instead of "registration", as it should be.
If someone can clear up my confusion, or if I'm correct about the above difference with how Apache and Nginx define REQUEST_URI, update the documentation accordingly.
Comment | File | Size | Author |
---|---|---|---|
#3 | drupal-2490870-3-by-axel.rutz-Use-request_uri-instead-o.patch | 1.16 KB | geek-merlin |
Comments
Comment #1
TheDigitalOrchard CreditAttribution: TheDigitalOrchard commentedUpdating the title since it was inaccurate.
Comment #2
geek-merlin@TheDigitalOrchard: I've been guessing a bit about the real cause, but if you feel i hijacked this, change back.
Comment #3
geek-merlinPatch flying in that fixes this.
Note that $_SERVER['REQUEST_URI'] is also used in install.inc's drupal_detect_baseurl(), but this function seems to be a zombie which is used nowhere. Leaving this for a folowup cleanup issue.