Created
July 7, 2017 15:04
-
-
Save nkeena/9db6cb85284b8b4616c5176854ef6f0f to your computer and use it in GitHub Desktop.
Middleware to redirect uppercase URLs to lowercase ones
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Middleware; | |
use Closure; | |
class RedirectToLowercase | |
{ | |
/** | |
* Handle an incoming request. | |
* | |
* @param \Illuminate\Http\Request $request | |
* @param \Closure $next | |
* @return mixed | |
*/ | |
public function handle($request, Closure $next) | |
{ | |
$path = $request->path(); | |
$pathLowercase = strtolower($path); // convert to lowercase | |
if ($path !== $pathLowercase) { | |
// redirect if lower cased path differs from original path | |
return redirect($pathLowercase); | |
} | |
return $next($request); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment