当我使用secure_url()
或asset()
时,它链接到我网站的域,而没有“ www”,即“ example.com”。
如何更改它以链接到“ www.example.com”?
最佳答案
首先在文件config / app.php中更改您的应用程序URL(或.env文件的APP_URL值):
'url' => 'http://www.example.com',
然后,使URL生成器使用它。在引导方法中将这些代码行添加到文件app / Providers / AppServiceProvider.php中:
\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 - Laravel:更改基本URL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35304448/