Make Ladill Link short URLs fully dynamic at click time.
Deploy Ladill Link / deploy (push) Successful in 1m55s

Forward query strings and path suffixes to the live destination, resolve public hosts from config/custom domains instead of hardcoding ladl.link, and keep proxy Location rewrites on the visitor host.
This commit is contained in:
isaacclad
2026-07-16 20:05:43 +00:00
parent a9ddd600db
commit d45f4b5c58
14 changed files with 195 additions and 28 deletions
+1 -1
View File
@@ -102,7 +102,7 @@ class AfiaService
What Ladill Link does and where things live:
- Overview (Dashboard): link count, recent clicks, and wallet balance.
- My Links: create, edit, enable/disable, and delete short links. Each new link debits a small fee from the Ladill wallet (see Settings or the create screen for the current price).
- Public URLs: default domain is ladl.link/{slug}. Links can also use a verified custom domain from Custom Domains.
- Public URLs: default domain is configured (usually ladl.link/{slug}) and always resolved live custom domains from Settings replace it when set as default.
- Analytics: click totals and trends across links.
- Custom Domains: connect a domain you own, verify DNS, and set a default domain for new links.
- Settings: default domain preference and account shortcuts.
@@ -103,11 +103,11 @@ class LinkCustomDomainService
public function isAppHost(string $host): bool
{
$host = preg_replace('/^www\./', '', strtolower(trim($host)));
$public = (string) config('customdomain.public_host', config('link.public_domain', 'ladl.link'));
$known = array_filter([
(string) config('customdomain.app_host'),
(string) config('customdomain.public_host'),
'ladl.link',
'www.ladl.link',
$public,
'www.'.$public,
]);
return in_array($host, $known, true);
+38 -6
View File
@@ -55,7 +55,7 @@ class LinkPlatformProxy
return $followUp;
}
$response->headers->set('Location', $this->rewriteLocation($location, $slug));
$response->headers->set('Location', $this->rewriteLocation($request, $location, $slug));
}
}
@@ -97,8 +97,7 @@ class LinkPlatformProxy
}
$host = strtolower((string) ($parsed['host'] ?? ''));
$linkHost = strtolower((string) parse_url(LadillLink::baseUrl(), PHP_URL_HOST));
if ($host !== $linkHost) {
if (! $this->isLinkPublicHost($host, $request)) {
return null;
}
@@ -111,6 +110,18 @@ class LinkPlatformProxy
return $this->forward($request, $slug, substr($path, strlen($slugPrefix)));
}
private function isLinkPublicHost(string $host, Request $request): bool
{
$host = preg_replace('/^www\./', '', strtolower($host)) ?: $host;
$candidates = array_filter([
strtolower((string) parse_url(LadillLink::baseUrl(), PHP_URL_HOST)),
strtolower((string) config('link.public_domain', 'ladl.link')),
strtolower((string) $request->getHost()),
]);
return in_array($host, $candidates, true);
}
private function isEventsRegistrationPath(string $path): bool
{
return $path === 'register'
@@ -179,14 +190,16 @@ class LinkPlatformProxy
return $flat;
}
private function rewriteLocation(string $location, string $slug): string
private function rewriteLocation(Request $request, string $location, string $slug): string
{
$publicBase = $this->publicBaseForRequest($request);
foreach ([$this->platformBaseUrl(), $this->eventsBaseUrl()] as $base) {
$prefix = $base.'/q/'.$slug;
if (str_starts_with($location, $prefix)) {
$suffix = substr($location, strlen($prefix));
return LadillLink::url($slug).$suffix;
return rtrim($publicBase, '/').'/'.$slug.$suffix;
}
}
@@ -194,9 +207,28 @@ class LinkPlatformProxy
if (str_starts_with($location, $transfer)) {
$suffix = substr($location, strlen($transfer));
return LadillLink::url($slug).$suffix;
return rtrim($publicBase, '/').'/'.$slug.$suffix;
}
return $location;
}
/** Keep the visitor on the host they used (custom domain or platform public domain). */
private function publicBaseForRequest(Request $request): string
{
$host = strtolower((string) $request->getHost());
$appHost = strtolower((string) (
config('customdomain.app_host')
?: (parse_url((string) config('app.url'), PHP_URL_HOST) ?: '')
));
// Dashboard host (link.ladill.com) is not a public short-link host.
if ($host === '' || $host === $appHost) {
return LadillLink::baseUrl();
}
$scheme = $request->getScheme() ?: 'https';
return $scheme.'://'.$host;
}
}