Laravel News
Follow
How to Redirect Uppercase URLs to Lowercase with Laravel Middleware
A Laravel middleware was created to redirect requests containing uppercase letters to their lowercase equivalents for SEO optimization, while preserving query parameters. The middleware checks if the request path differs from its lowercase version and if so, appends the query string to the lowercase path and redirects permanently. To register the middleware in Laravel 11, it's added to the web middleware group in the bootstrap/app.php file. The middleware can be excluded from routes using signed URLs or requiring case sensitivity. This solution offers simplicity and consistency across different app environments, eliminating the need for changes on new servers.