0

In two Symfony 4 instances, I get different results with the same code. In a twig template, I have the line

<img src="{{  asset('images/DM_logo.jpg')}}"/>

In the online server, all works well: i get the image and the generated URL is /images/DM_logo.jpg for the absolute URL http://mysite.mydomain.com/images/DM_logo.jpg

But, locally, with the access to http://localhost/mysite/, the generated url is /mysite/images/DM_logo.jpg for the absolute url http://localhost/mysite/images/DM_logo.jpg which generate a NotFoundHttpException.

If i change the template to

<img src="{{  asset('public/images/DM_logo.jpg')}}"/>

it works locally but not online...

I doesn't find how to use the same code online and locally. Advices?

  • What URL do you use to access your site when developing? `localhost`, or `localhost/public`? – yivi Nov 26 '19 at 13:20
  • It seems to be a server web configuration error. What do you use in the local environment? – Mcsky Nov 26 '19 at 15:39

1 Answers1

0

configure this

# config/services.yaml
parameters:
    router.request_context.host: 'example.org'
    router.request_context.base_url: 'my/path'
    asset.request_context.base_path: '%router.request_context.base_url%'

https://symfony.com/doc/current/routing.html#routing-generating-urls

tolgakaragol
  • 532
  • 4
  • 13