如何将用户从一个页面重定向到同一页面,但在子域中?
https://customer.sunvalleytek.com/login 至 http://test.com
http://subdomain.test.com 至 http://test.com/page/page2/123
http://subdomain.test.com/page/page2/123 至 https://test.com/catalog?r=44&color=red
因此,我想重定向并保存示例中subdomain.test.com
之后的所有内容。我该怎么办?
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';
}
答案 0 :(得分:1)
使用此
private function get_back_path($url, $domain, $subdomain)
{
$parts = parse_url($url);
$url = $parts['scheme'] . '://' . $subdomain . '.' . $domain;
if (isset($parts['path'])) {
$url .= $parts['path'];
}
if (isset($parts['query'])) {
$url .= '?' . $parts['query'];
}
if (isset($parts['fragment'])) {
$url .= $parts['fragment'];
}
return $url;
}
答案 1 :(得分:0)
您可以像redirect()-> away('http://example.com?id=2);一样使用redirect()-> away();