Case insensitive Laravel

How to determine case insensitivity (part) of a route?

Example:

Any use of capital letters in the fixed part of the route does not work:

I understand how I can make parameters like {parameter}, use the regex pattern using → with (), but this does not help me with the fixed part of the route, as described above.

+6
source share
3 answers

This can be solved by defining routes as follows:

Route::get('/{userId}/{profile}')->with('profile', '(?i)profile(?-i)'); 

Even smarter, define it as a pattern , then it will also be available in route groups.

 Route::pattern('profile', '(?i)profile(?-i)'); Route::get('/{userId}/{profile}'); 
+5
source

Adding patterns only works one route at a time, if you want all routes to be case insensitive, add this to your /app/filter.php file in the previous section:

I wrote the gist that does this: https://gist.github.com/samthomson/f670f9735d200773e543

Edit the /filters.php application to check the uppercase characters on the route and redirect them to the converted route.

0
source

For those using Apache, you can also do this:

In doing so, the top of your vhost file adds

 RewriteEngine On RewriteMap lowercase int:tolower 

and in .htaccess

 RewriteCond $1 [AZ] RewriteRule ^(.*)$ /${lowercase:$1} [R=301,L] 
0
source

All Articles