Skip to content

Commit 931d9cf

Browse files
authored
Merge pull request #1040 from lpheller/lpheller-fix-subdomains
Fix subdomains pointing to root path
2 parents b10bbf0 + 18d2adc commit 931d9cf

File tree

1 file changed

+20
-21
lines changed

1 file changed

+20
-21
lines changed

server.php

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -125,33 +125,32 @@ function valet_default_site_path($config)
125125
* Determine the fully qualified path to the site.
126126
* Inspects registered path directories, case-sensitive.
127127
*/
128-
$valetSitePath = null;
129-
$domain = array_slice(explode('.', $siteName), -1)[0];
130-
131-
foreach ($valetConfig['paths'] as $path) {
132-
if ($handle = opendir($path)) {
133-
while (false !== ($file = readdir($handle))) {
134-
if (! is_dir($path.'/'.$file)) continue;
135-
if (in_array($file, ['.', '..', '.DS_Store'])) continue;
136-
137-
// match dir for lowercase, because Nginx only tells us lowercase names
138-
if (strtolower($file) === $siteName) {
139-
$valetSitePath = $path.'/'.$file;
140-
break;
128+
function get_valet_site_path($valetConfig, $siteName, $domain)
129+
{
130+
$valetSitePath = null;
131+
foreach ($valetConfig['paths'] as $path) {
132+
if ($handle = opendir($path)) {
133+
while (false !== ($file = readdir($handle))) {
134+
if (! is_dir($path.'/'.$file)) continue;
135+
if (in_array($file, ['.', '..', '.DS_Store'])) continue;
136+
137+
// match dir for lowercase, because Nginx only tells us lowercase names
138+
if (strtolower($file) === $siteName || strtolower($file) === $domain) {
139+
$valetSitePath = $path.'/'.$file;
140+
}
141141
}
142-
if (strtolower($file) === $domain) {
143-
$valetSitePath = $path.'/'.$file;
144-
break;
142+
closedir($handle);
143+
144+
if ($valetSitePath) {
145+
return $valetSitePath;
145146
}
146147
}
147-
closedir($handle);
148-
149-
if ($valetSitePath) {
150-
break;
151-
}
152148
}
153149
}
154150

151+
$domain = array_slice(explode('.', $siteName), -1)[0];
152+
$valetSitePath = get_valet_site_path($valetConfig, $siteName, $domain);
153+
155154
if (is_null($valetSitePath) && is_null($valetSitePath = valet_default_site_path($valetConfig))) {
156155
show_valet_404();
157156
}

0 commit comments

Comments
 (0)