【问题标题】:Adding leading slash in urls在网址中添加前导斜杠
【发布时间】:2015-04-22 10:10:04
【问题描述】:

在 Laravel 中,我注意到一些代码,例如

public function index()
{
    ...
    redirect url('/home');
}

/home 中的前导斜杠似乎没有必要。 url('home') 仍然可以工作。最佳做法是什么?

【问题讨论】:

  • 选择一个并为整个项目执行...

标签: php laravel


【解决方案1】:

在重定向 url 的字符串中使用 / 是一种很好的做法。

假设您正在浏览domain.com/some-url/,如果您使用redirect("home"),它会将您重定向到domain.com/some-url/home。但是如果你使用redirect('/home'),它会将你重定向到domain.com/home

以斜杠开头的路径确保路径是绝对的 根目录而不是当前目录。详情请见this

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-08-21
    • 1970-01-01
    • 2010-11-25
    • 2017-11-30
    • 2018-11-14
    • 2017-05-12
    • 1970-01-01
    • 2015-06-21
    相关资源
    最近更新 更多