File: D:/HostingSpaces/SBogers10/vebon.komma.pro/app/KommaApp/Core/Middleware/DomainMiddleWare.php
<?php
namespace KommaApp\Core\Middleware;
use Closure;
use Illuminate\Http\Request;
class DomainMiddleware
{
/**
* In this method, that is fired before the request.
* We are going to check if there is an db alias.
* If true, we will fire a modified request.
* If not, we check for an alternative route
* and redirect with a 301
*
* @param $request
* @param Closure $next
* @return mixed
*/
public function handle(Request $request, Closure $next)
{
// Get domain
list($protocol,$domain) = explode('://',url());
// Redirect if not equal to the main domain
if( $domain != 'vebon-audit.nl' && getenv('APP_ENV') == 'production')
{
$location = 'https://vebon-audit.nl';
if($request->path() != '/') $location .= '/' . $request->path();
header("Location: " . $location,true,301);
exit;
}
return $next($request);
}
}