Laravel:更改基本 URL? [英] Laravel: Change base URL?

查看:41
本文介绍了Laravel:更改基本 URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用 secure_url()asset() 时,它会链接到我网站的域没有"www",即example.com".

When I use secure_url() or asset(), it links to my site's domain without "www", i.e. "example.com".

如何将其更改为链接到www.example.com"?

How can I change it to link to "www.example.com"?

推荐答案

首先在 config/app.php 文件中更改您的应用程序 URL(或 .env<的 APP_URL 值/strong> 文件):

First change your application URL in the file config/app.php (or the APP_URL value of your .env file):

'url' => 'http://www.example.com',

然后,让 URL 生成器使用它.在 boot 方法中将这些代码行添加到文件 app/Providers/AppServiceProvider.php 中:

Then, make the URL generator use it. Add thoses lines of code to the file app/Providers/AppServiceProvider.php in the boot method:

URL::forceRootUrl(Config::get('app.url'));    
// And this if you wanna handle https URL scheme
// It's not usefull for http://www.example.com, it's just to make it more independant from the constant value
if (Str::contains(Config::get('app.url'), 'https://')) {
    URL::forceScheme('https');
    //use URL:forceSchema('https') if you use laravel < 5.4
}

就是这样.

这篇关于Laravel:更改基本 URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆