Not case sensitive URL?


#1

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

EDIT
See the solution here.


#2

Most webservers run on linux, unix and so on.

These OS are always case sensitive!


#3

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?


#4

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?


#5

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.


#6

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!


#7

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.


#8

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


#9

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);
            }

        }
    )
    ));

#10

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

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

#11

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


#12

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?


#13

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é


#14

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.


#15

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