0

I am having the problem that all my links generated with the route() function of laravel resolve to the local IP of the webserver instead of the domain written in the APP_URL section of the .env file.

  • The APP_URL is set correctly
  • nginx configured properly

Actually rendered:

<a href="http://sub.domain.com/1">some product id</a>

What it should be like:

<a href="http://10.101.171.23/1">some product id</a>

Code in the view:

<a href="{{ route('products.show', $product->id) }}">some product id</a>
  • 1
    You should never post images of code. it is even easier to copy past the code the your question than making screenshot of it. That will also help people help you in case they need to correct your code (they just copy paste then correct it) – N69S Apr 10 '23 at 23:31

1 Answers1

1

You mostly have a proxy in place that redirects the trafic to your nginx, like a badly configured load balancer might do.

In HTTP request the domain is taken from the global variable $_SERVER and not from the .env config.

To fix the issue code wise, you can add this to your boot() method in AppServiceProvider.php

public function boot()
{
    URL::forceRootUrl(Config::get('app.url'));
}
N69S
  • 16,110
  • 3
  • 22
  • 36
  • try above solution. I think this https://stackoverflow.com/a/65415660/14344959 alternative solution also should works. please responde me if it doesn't works – Harsh Patel Apr 11 '23 at 05:01
  • i used the version you initially posted and it worked perfectly for me. in the meantime i found out that the environment where i was trying to fix this issue really has a badly configured proxy server and therefore the wrong url had been rendered. thanks for your answer, really appreciated it. – julian.wurzer Apr 11 '23 at 08:47