Broken url subpage multi language

Hi to all,

Hope someone could help me with this, probably a very easy thing to sort out but i’m finding myself helpless right now or just not looking in the proper place.

The issue is:
In my multilingual site, when i switch to the other language being french, the urls (for the images in this case) are modified:

  • wrong url adding an fr :
    mysite/ fr /assets/img/someimg.png
  • when in a subpage it adds fr and the parentfolder name:
    mysite/ fr / parentfolder /assets/img/someimg.png
  • instead of :

When its in the default language, there is no issue

Sorry if i’m not very clear, thanks in advance to anyone that could guide me through the solution.

could you post some code from your template where the image are called?
I thing you have an mistake in your vars/class calling. Sometimes it could be that you call $languages instead $language.

But for helping we need a little bit more information about what are you doing inside your code.


What generates the URL? Do you use the url() function?

Hi, thanks for the replies,

The images are called inside the footer snippet, in that way :
<img src= "<?php echo ('assets/img/someimage.png') ?>" >
There is no template for that.

Sorry @lukasbestle, I don’t really know what is generating the url, but i guess is probably this part which is inside the main menu:

<ul class="lang">
        <?php foreach($site->languages() as $language): ?>
        <li<?php e($site->language() == $language, ' class="active"') ?>>
          <a href="<?php echo $page->url($language->code()) ?>">
            <?php echo html($language->name()) ?>
        <?php endforeach ?>

I hope that help, let me know if i can give you more insights about what i’m probably doing wrong.

Ah, that makes sense. What I meant is the line:

<img src= "<?php echo ('assets/img/someimage.png') ?>" >

This simply echoes the string, which is a relative URL. It is interpreted by the browser.
You will need to change it to be the following (this builds an absolute URL on the server):

<img src= "<?php echo url('assets/img/someimage.png') ?>" > 

Three characters more and hopefully the solution. :smile:

1 Like

Adding the those three character worked perfectly ! Thanks a lot @lukasbestle it works :smiley: .