Laravel case insensitive routes

馋奶兔 提交于 2019-12-01 04:23:26

This can be solved by defining routes the following way:

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

Even smarter, define it as pattern, then it also becomes available in Route groups.

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

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

I wrote a gist which does this: https://gist.github.com/samthomson/f670f9735d200773e543

Edit your app/filters.php to check for uppercase characters in the route and redirect them to a converted route.

For those using Apache you could also do this:

At this the top of your vhost file add

RewriteEngine On
RewriteMap lowercase int:tolower 

and in your .htaccess

RewriteCond $1 [A-Z]
RewriteRule ^(.*)$ /${lowercase:$1} [R=301,L]
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!