Skip to content

Commit 83c690c

Browse files
authored
Merge pull request #1068 from stidges/fix/subdomains
Fix subdomain using root domain link
2 parents 78ee4bf + 1b3c025 commit 83c690c

File tree

1 file changed

+30
-13
lines changed

1 file changed

+30
-13
lines changed

server.php

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -128,23 +128,40 @@ function valet_default_site_path($config)
128128
function get_valet_site_path($valetConfig, $siteName, $domain)
129129
{
130130
$valetSitePath = null;
131+
131132
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-
}
133+
$handle = opendir($path);
134+
135+
if ($handle === false) {
136+
continue;
137+
}
138+
139+
$dirs = [];
140+
141+
while (false !== ($file = readdir($handle))) {
142+
if (is_dir($path.'/'.$file) && ! in_array($file, ['.', '..'])) {
143+
$dirs[] = $file;
144+
}
145+
}
146+
147+
closedir($handle);
148+
149+
// Note: strtolower used below because Nginx only tells us lowercase names
150+
foreach ($dirs as $dir) {
151+
if (strtolower($dir) === $siteName) {
152+
// early return when exact match for linked subdomain
153+
return $path.'/'.$dir;
141154
}
142-
closedir($handle);
143-
144-
if ($valetSitePath) {
145-
return $valetSitePath;
155+
156+
if (strtolower($dir) === $domain) {
157+
// no early return here because the foreach may still have some subdomains to process with higher priority
158+
$valetSitePath = $path.'/'.$dir;
146159
}
147160
}
161+
162+
if ($valetSitePath) {
163+
return $valetSitePath;
164+
}
148165
}
149166
}
150167

0 commit comments

Comments
 (0)