Laravel 强制使用 https

背景

前段时间给自己的网站安装了 SSL 证书,启用了 https。然而 laravel 本身并没有任何改变,资源引用、路由跳转都还是走的 http。

Laravel 强制使用 https

Providers\AppServiceProviderboot() 方法中添加以下代码:

URL::forceScheme('https');

<?php

namespace App\Providers;

use Illuminate\Support\Facades\URL;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        //
        if ($this->app->environment() !== 'local') {
            URL::forceScheme('https');
        }
    }

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
       //
    }
}

$this->app['request']->server->set('HTTPS', $this->app->environment() != 'local');

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        //
        //让Laravel支持https,且区分本地
        $this->app['request']->server->set('HTTPS', $this->app->environment() != 'local');
    }

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
       //
    }
}    
Responses
  1. This website was... how do I say it? Relevant!! Finally I've found something which helped me. Many thanks! 0mniartist asmr

    Reply
  2. Superb blog! Do you have any recommendations for aspiring writers? I'm planning to start my own website soon but I'm a little lost on everything. Would you propose starting with a free platform like Wordpress or go for a paid option? There are so many options out there that I'm totally confused .. Any suggestions? Many thanks! asmr 0mniartist

    Reply
  3. I have read so many articles or reviews about the blogger lovers however this piece of writing is actually a pleasant piece of writing, keep it up. asmr 0mniartist

    Reply
  4. We are a bunch of volunteers and opening a new scheme in our community. Your site provided us with helpful info to work on. You have performed a formidable process and our whole neighborhood will be grateful to you. asmr 0mniartist

    Reply
  5. Pretty nice post. I just stumbled upon your blog and wished to mention that I have truly enjoyed browsing your weblog posts. After all I'll be subscribing for your feed and I'm hoping you write once more soon! 0mniartist asmr

    Reply
  6. Dix

    Quotes are available at an end paragraph. Utilize them carefully. You are able to finish an article using a quotation which includes conciliatory and a troubling. Nevertheless, using a reiteration of one's thesis announcement, conclude decisions in my own estimation. http://thevisionmarketing.net/how-do-you-cite-two-authors-from-the-same-website/ http://christlifechurch.co.za/how-do-you-come-up-with-a-claim/ http://seeds.lava.mx/2021/03/28/how-do-you-cite-mla-with-multiple-authors/

    Reply