How to make routes case insensitive |
I've create API on CI4 and set all the routes then found out that all routes are case sensitive though I want to ignore case and match either way, how do I do it?
This should be routed with www.mydomain.com/api www.mydomain.com/Api $routes->group('api', function ($routes) { $routes->post('/', 'MyController::myFunction'); });
Never mind, I've implemented a function on $routes to ignore case;
$routes->setIgnoreCaseSensitive(true);
Be nice if you showed your code for the rest of the forum users.
What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
In system/Router/RouteCollection.php on Line no: 84
After protected $autoRoute = true; Add> /** * Whether to ignore case sensitive in URI. * * Not used here. Pass-thru value for Router class. * * @var boolean */ protected $ignoreCase = false; In system/Router/RouteCollection.php on Line no: 335 After public function setAutoRoute(bool $value) {...} Add> /** * Tells the system whether to ignore case in URI strings. * * @param boolean $value * * @return RouteCollectionInterface */ public function setIgnoreCaseSensitive(bool $value): RouteCollectionInterface { $this->ignoreCase = $value; return $this; } //-------------------------------------------------------------------- In system/Router/RouteCollection.php on Line no: 484 After public function shouldAutoRoute() {...} Add> /** * Returns the flag that tells whether to ignore case sensitivity in URI. * * @return boolean */ public function shouldIgnoreCaseSensitive(): bool { return $this->ignoreCase; } //-------------------------------------------------------------------- In system/Router/RouteCollectionInterface.php on Line no: 124 After public function setAutoRoute(bool $value): self; = true; Add> /** * Tells the system whether to ignore case in URI strings. * * @param boolean $value * * @return RouteCollectionInterface */ public function setIgnoreCaseSensitive(bool $value): self; //-------------------------------------------------------------------- In system/Router/RouteCollectionInterface.php on Line no: 176 After public function shouldTranslateURIDashes(); Add> /** * Returns the flag that tells whether to ignore case sensitivity in URI. * * @return boolean */ public function shouldIgnoreCaseSensitive(); //-------------------------------------------------------------------- In system/Router/Router.php on Line no: 407 After if (strpos($key, '{locale}') !== false){...} Add> if ($this->collection->shouldIgnoreCaseSensitive() === true) { $uri = strtolower($uri); $key = strtolower($key); } In app/Config/Routes.php Add anywhere> $routes->setIgnoreCaseSensitive(true); If you don't want to make changes then I've also attached the files just download and place them at system/Router/<downloaded files> ![]() ![]() ![]()
@UzairAli001,
I trap case insensitive URLs in Controllers: Code: # ========================================== |
Welcome Guest, Not a member yet? Register Sign In |