How can I redirect user from one page to the same page, but in subdomain?
http://test.com to http://subdomain.test.com
http://test.com/page/page2/123 to http://subdomain.test.com/page/page2/123
https://test.com/catalog?r=44&color=red to https://subdomain.test.com/catalog?r=44&color=red
So I want redirect and save all what present after subdomain.test.com in my example. How can I do it?
public function test($request)
    {
        $subdomain = Market::first()->subdomain;
        $domain = $this->get_domain($request);
        $protocol = $this->get_request_protocol($request);
        $to = $protocol . '://' . $subdomain . '.' . $domain; // all path and params?
        return Redirect::to($to);
    }
    private function get_domain($request)
    {
        $parts = explode('.', $request->getHost());
        $i = count($parts)-1;
        return implode('.', [$parts[$i-1], $parts[$i]]);
    }
    private function get_request_protocol($request)
    {
        if ($request->secure()) {
            return 'https';
        }
        return 'http';
    }
 
     
     
    