HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
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);
    }

}