Last active
March 6, 2019 08:08
-
-
Save joelhinz/bf196f2532cd4480e4721109ee949e12 to your computer and use it in GitHub Desktop.
Laravel 5 redirect index.php calls middleware
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 RedirectIndexPhpCalls | |
{ | |
/** | |
* Handle an incoming request. | |
* | |
* @param \Illuminate\Http\Request $request | |
* @param \Closure $next | |
* | |
* @return mixed | |
*/ | |
public function handle($request, Closure $next) | |
{ | |
if (preg_match('@/index\.php(/.+)?$@', $request->url(), $match)) { | |
return isset($match[1]) | |
? redirect(config('app.url').$match[1], 301) | |
: redirect(config('app.url'), 301); | |
} | |
return $next($request); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks! not the most elegant solution but on the other hand it is triggered only for bad requests from crawlers and it is inside of a repo and not in a server config.