symfony: prepareBaseUrl() Request bug
Take for instance you have a mod_rewrite in apache to redirect all requests through to index.php (common practice for “pretty” urls)
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
If you request for a url like: http://my-site.com/fruit/strawberry/index.php/blah the base url comes back as blah. I would expect the base to be / and segments to be fruit/strawberry/index.php/blah due to the mod_rewrite.
The issue is caused by the basename in the very top lines in prepareBaseUrl as below:
src/Symfony/Component/HttpFoundation/Request.php
/**
* Prepares the base URL.
*
* @return string
*/
protected function prepareBaseUrl()
{
$filename = basename($this->server->get('SCRIPT_FILENAME'));
if (basename($this->server->get('SCRIPT_NAME')) === $filename) {
$baseUrl = $this->server->get('SCRIPT_NAME');
My request looks as below:
REQUEST_URI = /fruit/test/index.php/blah
SCRIPT_FILENAME = E:/Sites/cc-new/public_html/index.php
SCRIPT_NAME = /index.php
Essentially what it’s doing is getting the SCRIPT_FILENAME, doing a basename which turns it into simply index.php.
Then SCRIPT_NAME goes through basename too so it end’s up doing index.php == index.php which is true then set’s the base as the SCRIPT_NAME i.e. simply index.php
This is incorrect, it should set the base to / only. Something weird is going on with the use of basename…?
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Comments: 21 (9 by maintainers)
I’m wondering why that is. Without the “enhanced” web server config PHP sets
$request->server->get('PATH_INFO')to the correct value, however$request->getPathInfo()returns an unusable value. IMHO that indicates that thegetPathInfo()logic is broken, not the web server config.Unfortunate but…
… as defence against compatibility issues?