# Sorting numbers in the URL

**URL:** <https://forum.getkirby.com/t/sorting-numbers-in-the-url/10555>\
**Category:** Questions\
**Tags:** v2\
**Created:** [June 2, 2018, 11:19pm UTC](https://forum.getkirby.com/t/sorting-numbers-in-the-url/10555 "2018-06-02T23:19:48Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![FUSS](https://avatars.discourse-cdn.com/v4/letter/f/7ba0ec/32.png) [@FUSS](https://forum.getkirby.com/u/FUSS)\
**Post date:** [June 2, 2018, 11:19pm UTC](https://forum.getkirby.com/t/sorting-numbers-in-the-url/10555/1 "2018-06-02T23:19:48Z")

</div>

Hello

there is one aspect to Kirby, that I don’t understand.

You link to a file like this:

a) `(file: impulspapier.pdf text: Impulspapier)`  
or  
b) `(link: /content/1-aktivitaeten/impulspapier.pdf text: Impulspapier)`  
if you have uploaded it to an other page.

If a user saves or mails the direct link then, she/he get’s

[http://domain.de/content/1-aktivitaeten/impulspapier.pdf](http://domain.de/content/1-aktivitaeten/impulspapier.pdf)

If I change the structure of the menu, the link will fail in both cases. In the URL of the html page, Kirby don’t insert the nummer in the URL.

[http://domain.de/aktivitaeten](http://domain.de/aktivitaeten)

Why does Kirby operate in this different ways relating to the “sorting numbers” ?

Regards

FUSS

---

<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:** [June 2, 2018, 11:42pm UTC](https://forum.getkirby.com/t/sorting-numbers-in-the-url/10555/2 "2018-06-02T23:42:09Z")

</div>

> [@FUSS](#):
>
> aktivitaeten/impulspapier.pdf

First of all, when referencing a file from another page, you don’t have to (nor should you) insert the sorting number:

```auto
(file: aktivitaeten/impulspapier.pdf) 

```

is sufficient (i.e. without the content folder and the sorting numbers). Kirby automatically generates the correct URL with the sorting number.

Secondly, Kirby has an internal router that finds the correct file. If you call a link like this:

```auto
http://www.dortmund-zu-fuss.de/aktivitaeten/stellungnahmen/Masterplan-Impulspapier-FUSS.pdf

```

You will be automatically redirected to

```auto
http://www.dortmund-zu-fuss.de/content/1-aktivitaeten/1-stellungnahmen/Masterplan-Impulspapier-FUSS.pdf

```

If you want Kirby to create links like this through the file or image Kirbytags, you can make copies of those tags and modify them accordingly.

To make Kirby create those permalinks to files, you can use a custom file method, see example here: [kirby-custom-methods/file-methods/permanent-url.php at master · texnixe/kirby-custom-methods · GitHub](https://github.com/texnixe/kirby-custom-methods/blob/master/file-methods/permanent-url.php)

Note that if you do this, all calls to file/image URLs go through the router.

---

<div class="post-metadata">

**Author:** ![FUSS](https://avatars.discourse-cdn.com/v4/letter/f/7ba0ec/32.png) [@FUSS](https://forum.getkirby.com/u/FUSS)\
**Post date:** [June 3, 2018, 11:30am UTC](https://forum.getkirby.com/t/sorting-numbers-in-the-url/10555/3 "2018-06-03T11:30:52Z")

</div>

Hello texnixe,

thank you. I tried it again and now it works.

> [@texnixe](#):
>
> If you want Kirby to create links like this through the file or image Kirbytags, you can make copies of those tags and modify them accordingly.
> 
> To make Kirby create those permalinks to files, you can use a custom file method, see example here: [https://github.com/texnixe/kirby-custom-methods/blob/master/file-methods/permanent-url.php](https://github.com/texnixe/kirby-custom-methods/blob/master/file-methods/permanent-url.php)

Means “like this” links without numbers?

Regards

FUSS

---

<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:** [June 3, 2018, 2:01pm UTC](https://forum.getkirby.com/t/sorting-numbers-in-the-url/10555/4 "2018-06-03T14:01:48Z")

</div>

> [@FUSS](#):
>
> Means “like this” links without numbers?

Yes, that’s what I meant.

Keep in mind that if you rename a page folder, even file l links without folder numbers will no longer be valid. If this is likely to happen, you might consider using a dedicated file folder.

---

<div class="post-metadata">

**Author:** ![FUSS](https://avatars.discourse-cdn.com/v4/letter/f/7ba0ec/32.png) [@FUSS](https://forum.getkirby.com/u/FUSS)\
**Post date:** [June 3, 2018, 4:30pm UTC](https://forum.getkirby.com/t/sorting-numbers-in-the-url/10555/5 "2018-06-03T16:30:13Z")

</div>

Hello

let’s me repeate it in own words.

If I want links to files without numbers, I can make a copy of the Kirbytags, e. g. file2. Then I write `(file2: aktivitaeten/impulspapier.pdf)` and the user gets `http://domain.de/content/aktivitaeten/impulspapier.pdf`instead of `http://domain.de/content/1-aktivitaeten/impulspapier.pdf`. Then I can change the order in den menu without destroying the direct link until I rename the page folder. That’s the same basic principle in Wordpress, even the implementation is different.

So I will agree with your last comment.

Furthermore, I have questions, to understand the philosophy of Kirby.

You wrote, that I could modify the Kirbytag file. In the handbook stands, where to save the modifyed Kirbytag.

[https://getkirby.com/docs/developer-guide/kirbytext/tags](https://getkirby.com/docs/developer-guide/kirbytext/tags)

But the side ist silent about where the default tags are saved.

Then you write.

> To make Kirby create those permalinks to files, you can use a custom file method, see example here: [https://github.com/texnixe/kirby-custom-methods/blob/master/file-methods/permanent-url.php](https://github.com/texnixe/kirby-custom-methods/blob/master/file-methods/permanent-url.php)

Then I add a short link in the impulspapier.pdf.txt in this field and this short link is independent of the pahe folder?

Regards

FUSS

---

<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:** [June 3, 2018, 9:54pm UTC](https://forum.getkirby.com/t/sorting-numbers-in-the-url/10555/6 "2018-06-03T21:54:31Z")

</div>

It works like this:

1. Create a new file `methods.php` in /`site/plugins` with the following code:

```auto
file::$methods['permanentURL'] = function($file) {
  $site = $file->site();
  $lang = $site->multilang() ? $site->language()->code() . '/' : '';
  return $site->url() . '/' . $lang . $file->page()->id() . '/' . $file->filename();
};

```

This is a custom file method that generates a link without the prepended numbers.

1. Copy the following code into `file.php`and save in /site/tags:

```auto
<?php
kirbytext::$tags['file'] = array(
  'attr' => array(
    'text',
    'class',
    'title',
    'rel',
    'target',
    'popup'
  ),
  'html' => function($tag) {

    // build a proper link to the file
    $file = $tag->file($tag->attr('file'));
    $text = $tag->attr('text');

    if(!$file) return $text;

    // use filename if the text is empty and make sure to
    // ignore markdown italic underscores in filenames
    if(empty($text)) $text = str_replace('_', '\_', $file->name());

    return html::a($file->permanentURL(), html($text), array( // this line uses the new method instead of the url() method
      'class' => $tag->attr('class'),
      'title' => html($tag->attr('title')),
      'rel' => $tag->attr('rel'),
      'target' => $tag->target(),
    ));

  }
);

```

This is an exact copy of the file tag from`/kirby/extensions/tags.php` with the only difference that it now uses the custom file method from above to create the url. The new tag thus overwrites the original tag.

In your text file, you call the tag as before:

```auto
(file: aktivitaeten/impulspapier.pdf)

```

If you don’t use the tag, but instead you want to get the URL of a file directly in your template, also use the above method instead of the url() method

```auto
if($file = page('aktivitaeten')->file('impulspapier.pdf')) {
 echo $file->permanentURL();
}

```

Hope this makes it clearer.

---

<div class="post-metadata">

**Author:** ![bvdputte](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/bvdputte/32/8179_2.png) [@bvdputte](https://forum.getkirby.com/u/bvdputte)\
**Post date:** [June 4, 2018, 1:16pm UTC](https://forum.getkirby.com/t/sorting-numbers-in-the-url/10555/7 "2018-06-04T13:16:14Z")

</div>

> [@texnixe](#):
>
> Secondly, Kirby has an internal router that finds the correct file.

Woah! I didn’t know this. Thx for the tip!

---

<div class="post-metadata">

**Author:** ![distantnative](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/distantnative/32/11319_2.png) [@distantnative](https://forum.getkirby.com/u/distantnative)\
**Post date:** [February 6, 2025, 5:28pm UTC](https://forum.getkirby.com/t/sorting-numbers-in-the-url/10555/8 "2025-02-06T17:28:02Z")

</div>


