Does the limit of 255 still apply in drupal 8?

The maximum alias length and maximum component length values default to 100 and have a limit of 255 from Pathauto. You should enter a value that is the length of the "alias" column of the url_alias database table minus the length of any strings that might get added to the end of the URL. The recommended and default value is 100.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

maxilein created an issue. See original summary.

rp7’s picture

Title: Maximum alias length still 255 » Increase maximum alias length to 1024 characters
Component: Miscellaneous » Code
Category: Task » Feature request
FileSize
2.82 KB

Drupal core supports aliases with a maximum length of 1024 characters (see the "alias" column in the "url_alias" table). Pathauto currently limits this to 255 characters. Patch attached increased this Pathauto enforced limit to 1024 characters to make it consistent with Drupal core.

rp7’s picture

Status: Active » Needs review
maxilein’s picture

Isn't there a function to get the drupal default alias length by some function - instead of hard-coding it?
(I searched without success - I don't have an orientation in the code for path aliases..)

rp7’s picture

Status: Needs review » Active

Putting this issue back to "Active".

Found out that on my installation, I have the following (well hidden) piece of custom code running:

  // Increase the maximum URL alias length to 1024 characters.
  $schema_definition = drupal_get_module_schema('system', 'url_alias');
  if (!empty($schema_definition['fields']['alias']['length'])) {
    $schema_definition['fields']['alias']['length'] = 1024;
    $schema = Database::getConnection()->schema();
    $schema->dropIndex('url_alias', 'alias_langcode_pid');
    $schema->changeField('url_alias', 'alias', 'alias', $schema_definition['fields']['alias']);
    $schema->addIndex('url_alias', 'alias_langcode_pid', $schema_definition['indexes']['alias_langcode_pid'], $schema_definition);
  }

This makes my earlier statement about Drupal core supporting aliases up to 1024 characters... completely false. :-/

@maxilein

Isn't there a function to get the drupal default alias length by some function - instead of hard-coding it?

The only option I currently see is reading the schema definition. Something in the lines of

use Drupal\Core\Path\AliasStorage;
$schema_definition = AliasStorage::schemaDefinition();
$max_length = $schema_definition['fields']['alias']['length'];

But I'm in doubt if this is a proper way of doing things.

Chris Charlton’s picture

FWIW, URL lengths can be up to 1024 bytes, not characters. The coincidence of that number made me think I should post this.

maxilein’s picture

255 * 4 bytes = 1020 bytes

BUT it seems that nowadays almost all browsers support much longer urls.

See a good discussion here: https://stackoverflow.com/questions/417142/what-is-the-maximum-length-of...

maxilein’s picture

It makes me like the idea of a Drupal function even more...

Chris Charlton’s picture

Safe is best. Anything above legacy lengths/limits should be an override/setting for those who want to adopt. I'm just thinking of the legacy sites and browsers some regions may still be stuck on.

maxilein’s picture

255 is too limiting for a modern cms.
We should at least enable a proper possibility, make it configurable and let each Admin decide on his/her own.

johnlutz’s picture

Rerolled patch against latest release 8.x-1.5.

Berdir’s picture

Status: Active » Closed (won't fix)

Pathauto doesn't control the storage, we can't just create aliases that are longer than what's allowed in the url_alias/path_alias table.

So I have no plans to change that.

daften’s picture

For anybody needing a solution, we've developed a small module that takes care of it: https://www.drupal.org/project/path_alias_length

Any feedback welcome there of course.