mirror of
https://github.com/LBRYFoundation/lbry.com.git
synced 2025-08-31 01:11:25 +00:00
Case insensitive URL
This commit is contained in:
parent
20ee0064ae
commit
1d1c0be4fe
1 changed files with 27 additions and 2 deletions
|
@ -59,7 +59,7 @@ class Controller
|
|||
$dispatcher = new Routing\Dispatcher($router->getData());
|
||||
return $dispatcher->dispatch($method, $uri);
|
||||
} catch (\Routing\HttpRouteNotFoundException $e) {
|
||||
return NavActions::execute404();
|
||||
return static::doLowerUriRedirectOr404($uri);
|
||||
} catch (\Routing\HttpMethodNotAllowedException $e) {
|
||||
Response::setStatus(405);
|
||||
Response::setHeader('Allow', implode(', ', $e->getAllowedMethods()));
|
||||
|
@ -163,7 +163,7 @@ class Controller
|
|||
Response::enableHttpCache();
|
||||
return ['page/' . $slug, []];
|
||||
} else {
|
||||
return NavActions::execute404();
|
||||
return static::doLowerUriRedirectOr404($slug);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -198,4 +198,29 @@ class Controller
|
|||
call_user_func($fn);
|
||||
}
|
||||
}
|
||||
|
||||
protected static function doLowerUriRedirectOr404($uri)
|
||||
{
|
||||
$router = static::getRouterWithRoutes();
|
||||
// $lowerUri = strtolower($uri);
|
||||
$lowerUri = '/news/lbry-evolves';
|
||||
if ($uri !== $lowerUri) {
|
||||
if (View::exists('page/' . $lowerUri) || static::checkForRoute($lowerUri, $router)) {
|
||||
return static::redirect($lowerUri, 308);
|
||||
}
|
||||
}
|
||||
return NavActions::execute404();
|
||||
}
|
||||
|
||||
protected static function checkForRoute($uri, $router)
|
||||
{
|
||||
$routerData = $router->getData();
|
||||
if (in_array($uri, $routerData->getStaticRoutes())) {
|
||||
return true;
|
||||
} elseif (in_array($uri, $routerData->getVariableRoutes())) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue