Commit ed7fc098 authored by Dominik Hebeler's avatar Dominik Hebeler

Added redirect to TLD

parent e86bd4ea
......@@ -16,6 +16,7 @@ class Kernel extends HttpKernel
protected $middleware = [
\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
\Fideloper\Proxy\TrustProxies::class,
\App\Http\Middleware\LocalizationRedirect::class,
// \App\Http\Middleware\VerifyCsrfToken::class,
];
......
<?php
namespace App\Http\Middleware;
use Closure;
use LaravelLocalization;
class LocalizationRedirect
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
// We only redirect to the TLDs in the production version
if(env("APP_ENV", "") !== "production"){
return $next($request);
}
$locale = LaravelLocalization::getCurrentLocale();
$host = $request->getHttpHost();
if($host !== "metager.de" && $locale == "de"){
$url = $request->url();
$url = str_replace($host, "metager.de", $url);
$url = preg_replace("/^http:\/\//", "https://", $url);
$url = preg_replace("/^(https:\/\/[^\/]+)\/de/", "$1", $url);
return redirect($url);
}
if($host !== "metager.es" && $locale == "es"){
$url = $request->url();
$url = str_replace($host, "metager.es", $url);
$url = preg_replace("/^http:\/\//", "https://", $url);
$url = preg_replace("/^(https:\/\/[^\/]+)\/es/", "$1", $url);
return redirect($url);
}
if($host !== "metager.org" && $locale == "en"){
$url = $request->url();
$url = str_replace($host, "metager.org", $url);
$url = preg_replace("/^http:\/\//", "https://", $url);
$url = preg_replace("/^(https:\/\/[^\/]+)\/en/", "$1", $url);
return redirect($url);
}
return $next($request);
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment