Sindbad~EG File Manager
<?php
namespace Common\Core\Middleware;
use Closure;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Http\Request;
class NormalizeUri
{
/**
* The application implementation.
*
* @var \Illuminate\Contracts\Foundation\Application
*/
protected $app;
/**
* Create a new middleware instance.
*
* @param \Illuminate\Contracts\Foundation\Application $app
*/
public function __construct(Application $app)
{
$this->app = $app;
}
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*
* @throws \Symfony\Component\HttpKernel\Exception\HttpException
*/
public function handle($request, Closure $next)
{
$this->normalizeRequestUri($request);
app('url')->forceRootUrl(config('app.url'));
return $next($request);
}
/**
* Remove sub-directory from request uri, so as far as laravel/symfony
* is concerned request came from public directory, even if request
* was redirected from root laravel folder to public via .htaccess
*
* This will solve issues where requests redirected from laravel root
* folder to public via .htaccess (or other) redirects are not working
* if laravel is inside a subdirectory. Mostly useful for shared hosting
* or local dev where virtual hosts can't be set up properly.
*
* @param Request $request
*/
private function normalizeRequestUri(Request $request)
{
$parsedUrl = parse_url(config('app.url'));
//if there's no subdirectory we can bail
if (!isset($parsedUrl['path'])) return;
$originalUri = $request->server->get('REQUEST_URI');
$subdirectory = $parsedUrl['path'];
$normalizedUri = str_replace($subdirectory, '', $originalUri);
//if uri starts with "/public" after normalizing,
//we can bail as laravel will handle this uri properly
if (preg_match('/^public/', ltrim($normalizedUri, '/'))) return;
$request->server->set('REQUEST_URI', $normalizedUri);
}
}
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists