ZF-2052: base url not detected when it has urlencoded characters
Description
When the base url has a space in it (or whatever urlencoded character I guess) the Zend_Controller_Request_Http object does not detect it properly.
A simple urldecode() inside Zend_Controller_Request_Http::setRequestUri() will fix that
Comments
Posted by Matthew Weier O'Phinney (matthew) on 2007-11-16T14:37:11.000+0000
Scheduling for 1.0.3
Posted by Matthew Weier O'Phinney (matthew) on 2008-02-19T09:33:43.000+0000
Patched in trunk and release-1.0 branch.
Posted by Matthew Weier O'Phinney (matthew) on 2008-03-06T10:57:05.000+0000
Changing this behaviour actually breaks many applications, particularly those that pull from getPathInfo(). I am reverting this change.
If you need this functionality, subclass the request object as follows:
Posted by Matthew Weier O'Phinney (matthew) on 2008-03-06T10:57:27.000+0000
Will not fix, as it breaks other behaviours.
Posted by Claude Duvergier (cduv) on 2011-01-26T03:33:46.000+0000
I'm suggesting another fix that won't change {{Zend_Controller_Request_Http::$_requestUri}}.
Context: I access my development Apache server via the following URL (a VirtualHost): http://devprojects.myself.local My multiple Zend-powered application are accessible from there. For example: http://devprojects.myself.local/myGreatZfApp/… But, for some, there are spaces in the name of the folder that contains the application. Hence they appears the URL as "%20" (eg. [http://devprojects.myself.local/another%20Zf App/public/]).
Problem: My problem is that, on theses projects, baseUrl is not correctly set: it stays empty (an empty string). By analysing the code of {{Zend_Controller_Request_Http::setBaseUrl()}} I found out that base URL is somehow firstly correctly detected (either via {{$_SERVER['SCRIPT_NAME']}} or {{$_SERVER['PHP_SELF']}}), stored in local variable {{$baseUrl}} but gets compared to {{Zend_Controller_Request_Http::_requestUri}}:
My opinion is the code doesn't make the difference between a file path on the server and an URL (that have it's own set of constraints): the two may be similar then have some small differences.
Steps to reproduce: - Create a blank new Zend application - Make it accessible via an URL that contains one or more spaces (eg. [http://127.0.0.1/my projects rep/The Application/]) - Print the base URL via {{Zend_Controller_Front::getInstance()->getBaseUrl()}} or {{Zend_View_Helper_BaseUrl::getBaseUrl()}} - Notice it's empty (should be "/my projects rep/The Application/")
Fix proposal: The simple following fix seems to do the trick (making the {{Zend_Controller_Request_Http::_requestUri}} going through {{urldecode()}}):
But, as I said, file paths and URLs shouldn't be considered as equals: thus I suggest to make {{$baseUrl}} (which is actually constructed from file paths) go through {{urlencode()}} instead:
Posted by Claude Duvergier (cduv) on 2011-01-26T06:47:56.000+0000
Please ignore my second proposal (applying {{urlencode()}} on {{$baseUrl}}) as ({{urlencode()}} hasn't the proper effect on base URL (spaces are changed to "+").
Additionally, I've noticed that with my first fix proposal (applying {{urldecode()}} to the request URI) when accessing to [http://127.0.0.1/my%20projects%20rep/…] (note the tailing "index.php"), base URL takes the wrong value "/my%20projects%20rep/The%20Application/public/index.php" (because, in that case, {{$baseUrl}} directly fully matches the request URI).