Home > Mobile >  Using one Laravel app from different domains - building urls issue
Using one Laravel app from different domains - building urls issue

Time:02-04

I searched for my issue in so many ways, but I don't seem to find the correct case, so I'm asking here.

I have a Laravel app which is installed on a server and everything works correct. The domain is set as HTTP only and is configured from AWS. However we need to have another domain which should work only from HTTPS. The HTTP domain is pointing to the server instance and the HTTPS one is pointing to a CloudFront distribution with origin the HTTP domain. The issue is that when I open the HTTPS domain, all of the links and images are loaded from the HTTP domain.

To be more concrete, let's say I have http://mysite-notsecure.example.com and https://mysite-secure.example.com. When I open http://mysite-notsecure.example.com everything works as it should and there are no issues. However when I open https://mysite-secure.example.com the site loads, also files like app.js and app.css load with the correct host, but things like fonts, images, links, etc, load from http://mysite-notsecure.example.com.

Because most of the urls are built with the url() function, I think the issue has something to do with APP_URL, which was first set to http://mysite-notsecure.example.com, but when I added the new domain, I set it to empty (APP_URL=), however the urls are still built the same way (I cleared config cache). What should I do in order for my site to build the urls according to the current host? I don't need any other change for the two domains. They should load everything exactly the same, only the host should remain and not redirect to the other domain.

CodePudding user response:

Well, turned out it wasn't Laravel's fault. Again.

I printed the contents of the $_SERVER variable on both domains and as expected, the host in both was the HTTP domain. I guess I should've said earlier that we're using CloudFront on the HTTPS domain. The problem was right there.

Turned out the Host header had to be added to the CF distribution behavior, so that it is not replaced with the origin's value (the origin is the http domain). After this was fixed, all the urls automatically appeared correctly.

CodePudding user response:

goto file .env and setup the APP_URL=https://mysite-secure.example.com/ and change href={{asset('folder-path')}} in layout or blades file

  •  Tags:  
  • Related