laravel 使用 Redirect::to() 重定向到另一个网站

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18606726/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 08:22:31  来源:igfitidea点击:

Redirecting to another website using Redirect::to()

laravellaravel-4url-redirection

提问by Andreyco

When I use Redirect::to($url)this is the result:

当我使用Redirect::to($url)这是结果:

http://localhost/http://mysite.com/foo/bar.html

But when I use Redirect::to('http://google.com')it goes to google just fine, any guess what my problem is?

但是当我使用Redirect::to('http://google.com')它去谷歌就好了,你猜我的问题是什么?

回答by Andreyco

You need to provide fully qualifying URL to Redirect::to()method, otherwise application base URL is prepended.

您需要为方法提供完全限定的 URL Redirect::to(),否则将附加应用程序基 URL。

$url = 'www.google.com';
// redirects to http://localhost:8888/www.google.com
return Redirect::to($url);

$url = 'http://google.com';
// redirects to http://google.com
return Redirect::to($url);

回答by user3301152

To redirect to an external domain, use a fully qualified url such as tiqeet.com

要重定向到外部域,请使用完全限定的 url,例如 tiqeet.com

in your controller, call a return Redirect::intended("your fully qualified domain");

在您的控制器中,调用 return Redirect::intended("yourfullyqualified domain");

hope it works for you. Used it in laravel 4.0

希望对你有效。在 Laravel 4.0 中使用它

回答by Anandan K

Route::get('/', function () {

  $url = 'YOUR DOMAIN NAME HERE';  //DOMAIN NAME MUST BE LIKE THIS : https://www.google.com/

  return Redirect::to($url);

});

In I'm using Laravel 5.5 only for API's so in web route file i redirected to my domain name if any one tried to open the API domain name its redirected to my same domain

在我仅将 Laravel 5.5 用于 API 中,因此在 Web 路由文件中,如果有人试图打开其重定向到我的同一个域的 API 域名,我将重定向到我的域名