Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

attila.kom's avatar

Getting mixed content error when viewing website over HTTPS

If you follow this link: http://boiling-temple-56134.herokuapp.com/ The website appears fine.

When you follow this link: https://boiling-temple-56134.herokuapp.com/ The css and js files aren't loaded and I'm given a mixed content error.

How would I fix this?

0 likes
13 replies
Cronix's avatar

because you're loading your assets using http://. To get it to work for both cases, leave off the http: and https:

//domain.com/css/custom.css

Then it will use http or https depending on how it was accessed

attila.kom's avatar

Hey Cronix, thanks for the reply. How would I change this? For example, I am referencing stylesheets using blade statements. i.e.

<link rel="stylesheet" href="{{ asset('vendor/bootstrap/css/bootstrap.min.css') }}">
Cronix's avatar

Are you wanting to run your whole site over https, or just parts of it?

attila.kom's avatar

The whole website. Ah okay, so I just replace asset with secure_asset and I should be fine?

Cronix's avatar
Cronix
Best Answer
Level 67

I'd set up a redirect for all http requests to go to https using .htaccess or in nginx so it can ONLY be accessed via https

Then I'd make your APP_URL set to use https https://yoursite.com

You can also add \URL::forceScheme('https'); to the boot() method of your AppServiceProvider.

5 likes
Cronix's avatar

After that, asset(), url(), secure_asset(), etc., will all return https

Snapey's avatar

Are you behind a load balancer such as cloudflare?

The issue there is that they terminate the https session before it hits your web server so Laravel thinks the user is requesting http:// and makes links using http

There are several threads on the forum about this problem. Just search for cloud flare

edit: duh moment, I see herokuapp.com in your url. Could be the same issue though.

1 like
attila.kom's avatar

Cronix, thank you for your answer! I added the code to the boot method and changed the APP_URL, however when I redirected all HTTP to HTTPS by modifying the .htaccess file I was getting an error in my browser ERR_TOO_MANY_REDIRECTS so I didn't change that, but it still works now with the other suggestions!

burt's avatar

I was helped

FIX mixed content

At the beginning of the file

/app/Http/routes.php

add:

URL::forceSchema('https');

rheyjohn's avatar

I'm new here in laracast and im very thankful .. it works tnx Cronix

wilpat's avatar

Hi, I encountered a similar issue and i solved it by following the instructions in the documentation

Note that since this is an issue on heroku, you would have to set proxies to * and headers to Request::HEADER_X_FORWARDED_AWS_ELB

2 likes
redhatRanger's avatar

thnx it helped. i should read the documentation more often rather than giving up....lol

Please or to participate in this conversation.