File URLs change when pages are moved or made invisible

We have seen this requirement more than once, so an option would be great :slight_smile:

3 Likes

It would be extremely useful and solves an integral problem with how the site works. This would be an essential update. Please please please consider this as an option.

I like using kirby, but for client work I have had to switch back to wordpress because of this very issue. There should be an easier way to active/deactivate pages without effecting content links elsewhere.

I look forward to the update!

2 Likes

Also, wanted to clarify.

I am not suggesting that you get rid of the numbering system or re-do the entire structure in which Kirby is built.

I am just suggesting that there should be a way to control visibility/invisibility and sorting without changing the sequence number that is assigned to the page upon it’s creation. The original numbers can definitely stay, as long as they stay fixed.

Thank you again, much appreciated.

1 Like

Well, if the numbers should be fixed, that would mean that we would get rid of the numbering system.

What Bastian proposed above is that we will provide an option that the file URLs without numbers are used, not an option to change the numbering system.

Have you tried Bastian’s code example? This should fix the issues you are having until we make this an option in Kirby.

1 Like

Yes, fixed numbers would not even make sense, because it would disable the possibility to change the order of pages.

The This can be implemented as a file object method, too—

kirby()->set('file::method', 'safeUrl', function ($file) {
  return $file->page()->url() . '/' . $file->filename();
};

Untested, but should make this a little cleaner in your templates!

1 Like

Unfortunately, this does not help when you use images in text area fields … So we would need a solution that takes care of those images as well.

Do you mean inside Kirbytext? Yes, that’s true. I think we should just add an option that will then be checked in $file->url() directly. Then it works everywhere.

Yep, that’s what I meant.

It was proposed to Add an underscore, instead of removing the number, which sounds like a good idea imho.

1 Like

I agree to this great idea.

But what’s about in an older post about needing a new request for this?

Is this a real and serious problem with Kirby’s core structure/underpinnings?

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

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?

If I look at $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)).

But this only works on multi-language sites!

Good luck!

Added:
thanks to @texnixe

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

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

This still produces a 404 error. :confused:

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

@PaulMorel:

What’s, if you only add:

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

I get an error:

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