fix removing ending slash of url
This commit is contained in:
parent
36925139db
commit
fdf2a82e2e
|
|
@ -2,17 +2,19 @@
|
||||||
|
|
||||||
namespace App\Http\Middleware;
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
class RemoveSlashMiddleware
|
class RemoveSlashMiddleware
|
||||||
{
|
{
|
||||||
public function handle($request, \Closure $next)
|
public function handle($request, \Closure $next)
|
||||||
{
|
{
|
||||||
if (substr($request->getRequestUri(), -1) == "/") {
|
if (substr($request->getRequestUri(), -1) == "/") {
|
||||||
$base_url = $request->getBaseUrl();
|
$base_dir = $request->getBaseUrl();
|
||||||
// try to remove slash at the end of current url
|
// try to remove slash at the end of current url
|
||||||
$new_url = substr($request->getRequestUri(), 0, -1);
|
$new_url = substr($request->getRequestUri(), 0, -1);
|
||||||
|
|
||||||
if ($new_url != $base_url) {
|
if ($new_url != $base_dir) {
|
||||||
return redirect(str_replace($base_url, '', $new_url));
|
return redirect(Str::replaceLast($base_dir, '', $new_url));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user