Jump to content
formulate

URL character limit is 128 - how to increase this?

Recommended Posts

I have a new project that uses extremely long page urls. I need to bump the 128 character limit to 256. Does anyone know how to do this?

As it is now, when creating a new page with a really long title (ie: more than 128 characters), the URL is getting truncated to 128 characters.

Thanks.

Edited by formulate
issue not resolved

Share this post


Link to post
Share on other sites

The initial install was a couple months ago, so it seems like an update is in order!

Thanks for the heads up dragan!

Share this post


Link to post
Share on other sites

Ouch, ok NOT solved.

The PW version I'm running is 3.0.131, much newer than 3.0.86 that addressed this issue.

What am I missing here? Do I need to configure something somewhere to allow more than the default 128 characters?

Share this post


Link to post
Share on other sites

Actually the fix/change @dragan mentioned above was about URL segments only. Page names are still limited to 128 characters as far as I can tell.

Share this post


Link to post
Share on other sites
2 minutes ago, teppo said:

Actually the fix/change @dragan mentioned above was about URL segments only. Page names are still limited to 128 characters as far as I can tell.

Yikes! This is a major issue for me. Any ideas about how to work around this?

A character limit of 128 on page names seems kind of messed up. I wonder what Ryan's logic is behind this decision. At least relaxing it to 256 would surely be acceptable?

Share this post


Link to post
Share on other sites

Ok, as a workaround I created a script that uses $sanitizer->pageName where I can set the maxlength option to 256. While this works, it doesn't solve the problem of my client creating pages and having correct URL's. I guess I can always hook in to the page save and rewrite the name, but that seems ridiculous. There has to be some easy way to tell processwire to just allow 256 character names when saving new pages.

Ok I was wrong. I thought for a moment my script worked, but it didn't. Even using $sanitizer->pageName with the maxlength set to 256 doesn't work. It gets overridden somewhere and truncated to 128.

Share this post


Link to post
Share on other sites
56 minutes ago, formulate said:

Yikes! This is a major issue for me. Any ideas about how to work around this?

A character limit of 128 on page names seems kind of messed up. I wonder what Ryan's logic is behind this decision. At least relaxing it to 256 would surely be acceptable?

The limit of 128 characters has been in place for many years now. Personally I don't see a huge issue in raising it, or at least allowing longer names but making this an optional feature, but in the end that's a decision for @ryan. You can always open a new issue at the processwire-requests repository, requesting support for longer page names and explaining your use case and need for these.

I can't remember if the reason for this limit has been discussed before. Browsers have some kind of limits in place, but these days those should be pretty much a non-issue as far as I can tell. Database level scalability probably shouldn't be a massive issue here either.

That being said, I must add that this might be the first time I've heard anyone requesting longer than 128 character page names – so while it may seem messed up to you, it seems to me that your use case is actually not a particularly common one. In fact for most sites page names longer than 128 characters would very likely result in usability issues, and – just for an example – for the sort of projects I usually work on I definitely wouldn't want to allow that. 128 characters is already much longer than what makes sense 🙂

As for workarounds, depending on your use case you might be able to use URL segments here instead. That's just one idea, though.

41 minutes ago, formulate said:

Ok I was wrong. I thought for a moment my script worked, but it didn't. Even using $sanitizer->pageName with the maxlength set to 256 doesn't work. It gets overridden somewhere and truncated to 128.

The name field in the pages table is varchar(128), so that's at least one place that will enforce the limit.

  • Like 3

Share this post


Link to post
Share on other sites

Teppo, you are of course right. Thanks for your diplomatic reply and placing some perspective on this.

This is a very edge case and the first time I've encountered this need. It's specific to this one project and unfortunately, necessary.

All major web browsers and the http spec itself have supported 2048 character URLs for nearly two decades now. Hence I find it interesting that PW's character limit is 128. However, I don't know the reasons behind it, be it database or other efficiency related issues.

Unfortunately segments won't solve my issue. I need the URL to be a direct match with the page title. I'll change the table varchar to 256 and see what happens - seems like it could be the culprit.

  • Like 2

Share this post


Link to post
Share on other sites
33 minutes ago, teppo said:

The name field in the pages table is varchar(128), so that's at least one place that will enforce the limit. 

Unfortunately this didn't work. Name field is now varchar(256) and the name is still being truncated at some point after $sanitizer->pageName happens.

I also changed InputfieldName to 256 and ensured InputfieldPageName was also 256. Still doesn't work.

Share this post


Link to post
Share on other sites

There are several places that 128 is forced:

https://github.com/processwire/processwire/blob/649d2569abc10bac43e98ca98db474dd3d6603ca/wire/core/Sanitizer.php#L415
https://github.com/processwire/processwire/blob/649d2569abc10bac43e98ca98db474dd3d6603ca/wire/core/Pages.php#L85
https://github.com/processwire/processwire/blob/649d2569abc10bac43e98ca98db474dd3d6603ca/wire/core/PagesNames.php#L49
https://github.com/processwire/processwire/blob/649d2569abc10bac43e98ca98db474dd3d6603ca/wire/core/PagesNames.php#L314
https://github.com/processwire/processwire/blob/341342dc5b1c58012ae7cb26cffe2c57cd915552/wire/modules/Inputfield/InputfieldPageName/InputfieldPageName.js#L60
https://github.com/processwire/processwire/blob/649d2569abc10bac43e98ca98db474dd3d6603ca/wire/modules/Inputfield/InputfieldText.module#L258

When creating a new page, it's the JS file that kicks in first and truncates it as the title is typed. You could override the JS one pretty easily (look at my PageRenameOptions for hints on how to do this), and also deal with the sanitizer by setting the name in a hook and resaving, and you could hook into InputfildText::processInput to deal with the dirty length truncation.

I think the hardest but might be dealing with nameMaxLength constants that get used in PagesNames.php in the pageNameFromFormat() method.

Definitely much easier to see if Ryan might relax the limit, or make it configurable 🙂

  • Like 5

Share this post


Link to post
Share on other sites
6 hours ago, formulate said:

Unfortunately segments won't solve my issue. I need the URL to be a direct match with the page title.

Not sure why this means URL segments can't be a solution. You hook Pages::added and put the title through $sanitizer->pageName and save it to a hidden field (full_page_name). Then in the parent page template you check the URL segment against full_page_name and render any matching page (and throw a 404 if none found).

For URLs to the pages you hook Page::path as per Ryan's case study and concatenate full_page_name to the parent URL. 

  • Like 2

Share this post


Link to post
Share on other sites

Adrain, thanks for your time and input on this. Definitely easier to have Ryan relax the limit.

Robin, that is a clever solution with URL segments. While I don't normally like work-arounds like this, it may be the only solution at this point.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...