Not case sensitive URL?

Is it possible to have case in-sensitive urls for kirby?

EDIT
See the solution here.

Most webservers run on linux, unix and so on.

These OS are always case sensitive!

I was thinking I could use strtolower the url before kirby hits the disk. Yes file system is case-sensative, but the application sits in front of that. Is there a hook or something I could use to do this?

If you create a new page, the url is generated with lower case letters anyway. Do you want to change all existing urls or if a user has edited a URL?

Not looking to do anything on panel side, just on the display side. All urls coming into Kirby should be transformed into lowercase before Kirby looks for that page. I’m thinking it can be done with a Hook or Route, but not 100% sure how.

If you are using the panel e.g. for uploading of files, you can set an option:

Kirby docs: Panel > Blueprints > File Settings > Sanitization

But my hint is:
Never use capital letters in file names or directory names!

I am not trying to use capital letters in my urls, I know that’s bad. It’s actually the opposite, I am using all lowercase urls, but if someone types capital letters in their browser I don’t want it to 404.

Please read what I wrote before:

Not looking to do anything on panel side, just on the display side. All urls coming into Kirby should be transformed into lowercase before Kirby looks for that page. I’m thinking it can be done with a Hook or Route, but not 100% sure how.

Hooks are for use with the panel, so routes is what your are after.

For anyone wondering, this is how I was able to do this:

c::set('routes', array(
    array(
        'pattern' => '(:any)',
        'action'  => function($uid) {

            // Does the url contain uppercase characters?
            if (preg_match("/[A-Z]/", $uid)===1) {
                // Redirect to lowercase url
                go(strtolower($uid));
            } else {
                return site()->visit($uid);
            }

        }
    )
    ));
1 Like

Untested, but you could probably get away with the following in your config:

kirby()->path = strtolower(kirby()->path);
1 Like

Hello

Actually kirby is converting the title field to a lower case string for the URL-prefix. Is there any possibility that the URL can be case sensitive (containe upper and lower URL segements)?

Many thanks in advance

I don’t think so. Even if you change the slug manually in the page create form, Kirby will save a lowercase string. So you would have to use a hook to change the slug after creation, but I’m not sure this is even possible, because Kirby will probably sluggify that string as well.

What is your use case for having mixed case URLs?

1 Like

Hello texnixe

Many thanks again for your answer. Mixed cases in URLs has more to do with legibility (and also with aesthetics).

…/projects/PR2018001/ looks better than …/projects/pr2018001/

the same with abbreviations

…/projects/BSWillerGutBachstr/ is more readable than …/projects/bswillergutbachstr/

best regards,

André

The way you could achieve this would be to use a custom field that stores your desired URL string in combination with a custom page model that modifies the URL method to use that string instead of the UID in URLs and then use routes to find the correct page. However, I don’t think this is a great idea as it will slow down your site.

I noticed that if the page is not created by a kirby panel, but manually, the character case of the page folder and also the URL is not altered. Thus as I will create/generate and modify our project pages outside of kirby, I can have/maintain the mixed case URL .

best regards