# File URLs change when pages are moved or made invisible

**URL:** <https://forum.getkirby.com/t/file-urls-change-when-pages-are-moved-or-made-invisible/5348>\
**Category:** Questions\
**Tags:** v2\
**Created:** [September 28, 2016, 11:32am UTC](https://forum.getkirby.com/t/file-urls-change-when-pages-are-moved-or-made-invisible/5348 "2016-09-28T11:32:22Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![lukasbestle](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/lukasbestle/32/11437_2.png) [@lukasbestle](https://forum.getkirby.com/u/lukasbestle)\
**Post date:** [October 1, 2016, 8:59am UTC](https://forum.getkirby.com/t/file-urls-change-when-pages-are-moved-or-made-invisible/5348/21 "2016-10-01T08:59:56Z")

</div>

No. As we wrote above, Kirby already supports file URLs without the sorting numbers. 🙂

---

<div class="post-metadata">

**Author:** ![PaulMorel](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/paulmorel/32/371_2.png) [@PaulMorel](https://forum.getkirby.com/u/PaulMorel)\
**Post date:** [January 30, 2017, 6:30pm UTC](https://forum.getkirby.com/t/file-urls-change-when-pages-are-moved-or-made-invisible/5348/22 "2017-01-30T18:30:44Z")

</div>

> [@bastianallgeier](#):
>
> For now you can do:
> 
> ```php
> <?= $page->url() . '/' . $file->filename() ?>
> 
> ```
> 
> in your templates to get the static URL to the files. We might consider adding an option to make this the default if you have to have this.

This doesn’t seem to work for multi language websites. It only works in the default language and throws 404 errors in the other languages.

Is this normal or am I doing something wrong?

---

<div class="post-metadata">

**Author:** ![anon77445132](https://avatars.discourse-cdn.com/v4/letter/a/4da419/32.png) [@anon77445132](https://forum.getkirby.com/u/anon77445132)\
**Post date:** [January 30, 2017, 8:56pm UTC](https://forum.getkirby.com/t/file-urls-change-when-pages-are-moved-or-made-invisible/5348/23 "2017-01-30T20:56:08Z")

</div>

> [@PaulMorel](#):
>
> \<?= $page-\>url() . ‘/’ . $file-\>filename() ?\>

If I look at [$page-\>url()](https://getkirby.com/docs/cheatsheet/page/url) I think (sorry not tested yet) you can add in the **first** brackets something like `$site->language()` or `$site->language()->code()` (look at [$site-\>language($code = null)](https://getkirby.com/docs/cheatsheet/site/language)).

But this only works on multi-language sites!

Good luck!

Added:  
thanks to @texnixe

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [January 30, 2017, 9:00pm UTC](https://forum.getkirby.com/t/file-urls-change-when-pages-are-moved-or-made-invisible/5348/24 "2017-01-30T21:00:32Z")

</div>

You can pass the language code to the `url()` method: [https://getkirby.com/docs/cheatsheet/page/url](https://getkirby.com/docs/cheatsheet/page/url)

```auto
<?= $page->url($site->language()->code()) . '/' . $file->filename() ?>

```

---

<div class="post-metadata">

**Author:** ![PaulMorel](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/paulmorel/32/371_2.png) [@PaulMorel](https://forum.getkirby.com/u/PaulMorel)\
**Post date:** [January 30, 2017, 9:04pm UTC](https://forum.getkirby.com/t/file-urls-change-when-pages-are-moved-or-made-invisible/5348/25 "2017-01-30T21:04:38Z")

</div>

This still produces a 404 error. 😕

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [January 30, 2017, 9:05pm UTC](https://forum.getkirby.com/t/file-urls-change-when-pages-are-moved-or-made-invisible/5348/26 "2017-01-30T21:05:19Z")

</div>

What does the generated URL look like? Are you using URL keys?

---

<div class="post-metadata">

**Author:** ![anon77445132](https://avatars.discourse-cdn.com/v4/letter/a/4da419/32.png) [@anon77445132](https://forum.getkirby.com/u/anon77445132)\
**Post date:** [January 30, 2017, 9:06pm UTC](https://forum.getkirby.com/t/file-urls-change-when-pages-are-moved-or-made-invisible/5348/27 "2017-01-30T21:06:49Z")

</div>

@PaulMorel:

What’s, if you only add:

> [@anon77445132](#):
>
> $site-\>language()

---

<div class="post-metadata">

**Author:** ![PaulMorel](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/paulmorel/32/371_2.png) [@PaulMorel](https://forum.getkirby.com/u/PaulMorel)\
**Post date:** [January 30, 2017, 9:12pm UTC](https://forum.getkirby.com/t/file-urls-change-when-pages-are-moved-or-made-invisible/5348/28 "2017-01-30T21:12:14Z")

</div>

> [@texnixe](#):
>
> What does the generated URL look like? Are you using URL keys?

For both `$page->url($site->language()->code())` and `$page->url()`, the URL is the same.

`http://example.com/fr/premiere-page/deuxieme-page/document.pdf`

In the english version, the link works.

`http://example.com/en/first-page/second-page/document.pdf`

> [@anon77445132](#):
>
> @PaulMorel:
> 
> What’s, if you only add:
> 
> HeinerEF:  
> $site-\>language()

I get an error:

`Whoops \ Exception \ ErrorException (E_WARNING) Illegal offset type in isset or empty`

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [January 30, 2017, 9:12pm UTC](https://forum.getkirby.com/t/file-urls-change-when-pages-are-moved-or-made-invisible/5348/29 "2017-01-30T21:12:25Z")

</div>

I did a quick test and the URL that is generated by that code looks alright and the link works for me (tested in a 2.4.1 Langkit)

```auto
<?
$image = $page->images()->first() ?>
<a href="<?= $page->url($site->language()->code()) . '/' . $image->filename() ?>">link to image</a>

```

Edit: `$site->language()` will not work.

---

<div class="post-metadata">

**Author:** ![anon77445132](https://avatars.discourse-cdn.com/v4/letter/a/4da419/32.png) [@anon77445132](https://forum.getkirby.com/u/anon77445132)\
**Post date:** [January 30, 2017, 9:15pm UTC](https://forum.getkirby.com/t/file-urls-change-when-pages-are-moved-or-made-invisible/5348/30 "2017-01-30T21:15:05Z")

</div>

May be

> [@PaulMorel](#):
>
> /fr/

is your default language, which is omitted in the path by default?

Then I would try to omit it here too…

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [January 30, 2017, 9:17pm UTC](https://forum.getkirby.com/t/file-urls-change-when-pages-are-moved-or-made-invisible/5348/31 "2017-01-30T21:17:30Z")

</div>

The resulting HTML, without lang code in the default language

```auto
<a href="http://localhost/alang/de/projects/project-a/closeup.jpg">link to image</a>
<a href="http://localhost/alang/projects/project-a/closeup.jpg">link to image</a>

```

Which Kirby version are you using and what does your language setup look like in config.php?

---

<div class="post-metadata">

**Author:** ![PaulMorel](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/paulmorel/32/371_2.png) [@PaulMorel](https://forum.getkirby.com/u/PaulMorel)\
**Post date:** [January 30, 2017, 9:20pm UTC](https://forum.getkirby.com/t/file-urls-change-when-pages-are-moved-or-made-invisible/5348/32 "2017-01-30T21:20:54Z")

</div>

@anon77445132: en is my default, but my config might be wrong.

@texnixe: Right now I’m on 2.4.0. I’ll update to 2.4.1 tomorrow see if it makes a difference. Here’s my language config:

```php
c::set('languages', array(
  array(
    'code' => 'en',
    'name' => 'English',
    'default' => true,
    'locale' => 'en_CA',
    'url' => '/en',
  ),
  array(
    'code' => 'fr',
    'name' => 'Français',
    'locale' => 'fr_CA',
    'url' => '/fr',
  ),
));

```

---

<div class="post-metadata">

**Author:** ![anon77445132](https://avatars.discourse-cdn.com/v4/letter/a/4da419/32.png) [@anon77445132](https://forum.getkirby.com/u/anon77445132)\
**Post date:** [January 30, 2017, 9:21pm UTC](https://forum.getkirby.com/t/file-urls-change-when-pages-are-moved-or-made-invisible/5348/33 "2017-01-30T21:21:03Z")

</div>

@PaulMorel:

It should look like

```php
<a href="http://example.com/fr/premiere-page/deuxieme-page/document.pdf">link to image - fr</a>
<a href="http://example.com/en/first-page/second-page/document.pdf">link to image - en</a>

```

What happens, if you you add something like my above code as a static text (with correct links) in a textarea, which is renderd with `kirbytext( ... )`?

Added:

```php
<?php if($site->multilang()): ?>
This is a multi-language website
<?php endif ?>

```

works correct?

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [January 30, 2017, 9:23pm UTC](https://forum.getkirby.com/t/file-urls-change-when-pages-are-moved-or-made-invisible/5348/34 "2017-01-30T21:23:16Z")

</div>

Since you are using the language code for both languages, the urls should have that as well, so your links are in fact correct.

Edit: But the error occurs once I add an URL-Key, so that does look more like a bug.

The interesting thing is that without URL-Key, the correct link with lang code reroutes to an image URL without the lang code.

Edit: I created an [issue on GitHub](https://github.com/getkirby/kirby/issues/547).

---

<div class="post-metadata">

**Author:** ![PaulMorel](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/paulmorel/32/371_2.png) [@PaulMorel](https://forum.getkirby.com/u/PaulMorel)\
**Post date:** [January 30, 2017, 9:38pm UTC](https://forum.getkirby.com/t/file-urls-change-when-pages-are-moved-or-made-invisible/5348/35 "2017-01-30T21:38:01Z")

</div>

> [@anon77445132](#):
>
> Added:
> 
> \<?php if($site-\>multilang()): ?\>  
> This is a multi-language website  
> \<?php endif ?\>
> 
> works correct?

Yeah, that works. Hardcoding the links in the text area does the same. I get a 404 on the french link.

> [@texnixe](#):
>
> Edit: But the error occurs once I add an URL-Key, so that does look more like a bug.
> 
> The interesting thing is that without URL-Key, the correct link with lang code reroutes to an image URL without the lang code.

Hmm, I should’ve specified that I was using URL-Key for the french language.

At least now know that it’s a bug.

---

<div class="post-metadata">

**Author:** ![anon77445132](https://avatars.discourse-cdn.com/v4/letter/a/4da419/32.png) [@anon77445132](https://forum.getkirby.com/u/anon77445132)\
**Post date:** [January 30, 2017, 9:41pm UTC](https://forum.getkirby.com/t/file-urls-change-when-pages-are-moved-or-made-invisible/5348/36 "2017-01-30T21:41:32Z")

</div>

@PaulMorel:  
What is the working link to the file with the numbers from the visible pages sort for the french version of that webpage?

I don’t know about the translated directory names in such a link…

Added:  
I want to know your normal link with the sort numbers of the directories to think of a solution…

---

<div class="post-metadata">

**Author:** ![anon77445132](https://avatars.discourse-cdn.com/v4/letter/a/4da419/32.png) [@anon77445132](https://forum.getkirby.com/u/anon77445132)\
**Post date:** [January 30, 2017, 9:46pm UTC](https://forum.getkirby.com/t/file-urls-change-when-pages-are-moved-or-made-invisible/5348/37 "2017-01-30T21:46:16Z")

</div>

What’s about to use only

> [@anon77445132](#):
>
> \<a href=“[http://example.com/en/first-page/second-page/document.pdf](http://example.com/en/first-page/second-page/document.pdf)”\>

for **BOTH** languages, if you link to the same file?

Added:  
This may be a work around until the Kirby code get’s corrected…

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [January 30, 2017, 9:48pm UTC](https://forum.getkirby.com/t/file-urls-change-when-pages-are-moved-or-made-invisible/5348/38 "2017-01-30T21:48:06Z")

</div>

If we use a standard image link, neither the lang code nor the URL-Keys are used:

```auto
<a href="http://localhost/alang/content/1-projects/1-project-a/closeup.jpg">link to image</a>

```

The link is always the same, no matter if default language or not.

---

<div class="post-metadata">

**Author:** ![anon77445132](https://avatars.discourse-cdn.com/v4/letter/a/4da419/32.png) [@anon77445132](https://forum.getkirby.com/u/anon77445132)\
**Post date:** [January 30, 2017, 9:49pm UTC](https://forum.getkirby.com/t/file-urls-change-when-pages-are-moved-or-made-invisible/5348/39 "2017-01-30T21:49:38Z")

</div>

I think, we want NOT to use the sort numbers…

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [January 30, 2017, 9:52pm UTC](https://forum.getkirby.com/t/file-urls-change-when-pages-are-moved-or-made-invisible/5348/40 "2017-01-30T21:52:56Z")

</div>

This should work:

```auto
<? $image = $page->images()->first() ?>
<a href="<?= $site->url() . DS . $page->id() . DS . $image->filename() ?>">link to image</a>

```

It creates the link without language code and without the URL key, in the same way the standard, numbered image link is created, only without the content folder and without the numbers.

[Previous page](https://forum.getkirby.com/t/file-urls-change-when-pages-are-moved-or-made-invisible/5348.md?page=1)

[Next page](https://forum.getkirby.com/t/file-urls-change-when-pages-are-moved-or-made-invisible/5348.md?page=3)
