dtjbcda841554 2016-05-30 05:01 采纳率: 0%
浏览 215

如何通过https在Laravel 5中提供静态内容?

I've spent a ton of time trying to fix this but haven't had any luck so far. My app isn't loading css because of a mixed content error (The page at 'https://example.com/' was loaded over HTTPS, but requested an insecure stylesheet 'http://example.com/assets/css/magazine.min.css'. This request has been blocked; the content must be served over HTTPS). I know that I can load the assets by passing in true to the asset function but that would mean I would have to go to all the asset calls and change them. Is there a site wide setting I can configure so that it does https in production and http in local?

Thanks

  • 写回答

3条回答 默认 最新

  • dqd2800 2016-05-30 11:19
    关注

    You can create something like ForceHttps middleware and than create condition for environment inside of it, like this:

    public function handle($request, Closure $next)
    {
        if (!\App::environment('local')) {
            \URL::forceSchema('https');
        }
    
        return $next($request);
    }
    

    Than add it to some route group or globally if you want.

    NOTE: I would suggest to resolve this on your web server, not in Laravel

    评论

报告相同问题?

悬赏问题

  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)