Skip to content

Instantly share code, notes, and snippets.

@joelhinz
Last active March 6, 2019 08:08
Show Gist options
  • Save joelhinz/bf196f2532cd4480e4721109ee949e12 to your computer and use it in GitHub Desktop.
Save joelhinz/bf196f2532cd4480e4721109ee949e12 to your computer and use it in GitHub Desktop.
Laravel 5 redirect index.php calls middleware
<?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);
}
}
@aurawindsurfing
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment