Skip to content

Commit 9eeb37e

Browse files
mvoriseknicolas-grekas
authored andcommitted
[HttpFoundation] Fix for virtualhosts based on URL path
1 parent 889007a commit 9eeb37e

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

Request.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1848,9 +1848,15 @@ protected function prepareBaseUrl()
18481848
}
18491849

18501850
$basename = basename($baseUrl);
1851-
if (empty($basename) || !strpos(rawurldecode($truncatedRequestUri), $basename)) {
1852-
// no match whatsoever; set it blank
1853-
return '';
1851+
if (empty($basename) || !strpos(rawurldecode($truncatedRequestUri).'/', '/'.$basename.'/')) {
1852+
// strip autoindex filename, for virtualhost based on URL path
1853+
$baseUrl = \dirname($baseUrl).'/';
1854+
1855+
$basename = basename($baseUrl);
1856+
if (empty($basename) || !strpos(rawurldecode($truncatedRequestUri).'/', '/'.$basename.'/')) {
1857+
// no match whatsoever; set it blank
1858+
return '';
1859+
}
18541860
}
18551861

18561862
// If using mod_rewrite or ISAPI_Rewrite strip the script filename

Tests/RequestTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1763,6 +1763,36 @@ public function getBaseUrlData()
17631763
'/foo',
17641764
'/bar+baz',
17651765
],
1766+
[
1767+
'/sub/foo/bar',
1768+
[
1769+
'SCRIPT_FILENAME' => '/home/John Doe/public_html/foo/app.php',
1770+
'SCRIPT_NAME' => '/foo/app.php',
1771+
'PHP_SELF' => '/foo/app.php',
1772+
],
1773+
'/sub/foo',
1774+
'/bar',
1775+
],
1776+
[
1777+
'/sub/foo/app.php/bar',
1778+
[
1779+
'SCRIPT_FILENAME' => '/home/John Doe/public_html/foo/app.php',
1780+
'SCRIPT_NAME' => '/foo/app.php',
1781+
'PHP_SELF' => '/foo/app.php',
1782+
],
1783+
'/sub/foo/app.php',
1784+
'/bar',
1785+
],
1786+
[
1787+
'/sub/foo/bar/baz',
1788+
[
1789+
'SCRIPT_FILENAME' => '/home/John Doe/public_html/foo/app2.phpx',
1790+
'SCRIPT_NAME' => '/foo/app2.phpx',
1791+
'PHP_SELF' => '/foo/app2.phpx',
1792+
],
1793+
'/sub/foo',
1794+
'/bar/baz',
1795+
],
17661796
];
17671797
}
17681798

0 commit comments

Comments
 (0)