Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Mithridates's avatar

How do I make routes case insensitive?

I have a route:

route::get('/user/register','UsersController@show);

but this route returns not Found exception:

site.dev/User/register

how do I make all routes case insensitive?

0 likes
8 replies
willvincent's avatar

I don't know that you'd necessarily want routes to be accessible at both /user/... and /User/... might take a hit against SEO that way.

You'd probably be better off using some middleware to rewrite paths to lowercase then redirect with a 301 if the initial request wasn't all lowercase.

Why would you have links with improperly cased paths to begin with though?

4 likes
Mithridates's avatar

@willvincent, I thought it was common that sites respond to a route ignoring the lower or upper case. But seems like it's not true, right?

Snapey's avatar

This might cause problems elsewhere but you can strToLower in your index.php file

I have added the GLOBALS line. Now it does not matter about the case, but by the same token, its not possible to use case to differentiate routes or pass mixed case parameters;

$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);

$GLOBALS['_SERVER']['REQUEST_URI'] = strtolower($GLOBALS['_SERVER']['REQUEST_URI']);

$response = $kernel->handle(
    $request = Illuminate\Http\Request::capture()
);

$response->send();

$kernel->terminate($request, $response);
Mithridates's avatar

Thanks all, It comes out that this is not a common pattern at all, so I ignore it as well!

callam's avatar

@Mithridates I implemented this when a user wanted a short link to redirect users to their event page. The URL was printed on posters with a capital letter at the beginning and people were typing it in lowercase, this solved the issue.

Route::get('/foo/{bar}', function ($bar) {
    switch (strtolower($bar)) {
        case 'baz':
            return Redirect::to('/foo/baz')
        default:
            break;
    }
});
1 like

Please or to participate in this conversation.