Laravel:更改基本 URL?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35304448/
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
Laravel: Change base URL?
提问by user5893820
When I use secure_url()
or asset()
, it links to my site's domain without"www", i.e. "example.com".
当我使用secure_url()
或 时asset()
,它链接到我网站的域,没有“www”,即“example.com”。
How can I change it to link to "www.example.com"?
如何将其更改为链接到“www.example.com”?
回答by Synn
First change your application URL in the file config/app.php(or the APP_URL value of your .envfile):
首先在文件config/app.php(或.env文件的 APP_URL 值)中更改您的应用程序 URL :
'url' => 'http://www.example.com',
Then, make the URL generator use it. Add thoses lines of code to the file app/Providers/AppServiceProvider.phpin the bootmethod:
然后,让 URL 生成器使用它。将这些代码行添加到boot方法中的文件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
}
That's all folks.
这就是所有的人。