When generating a new url when the same url is already exists, pathauto creates urls with postfixes -0 -1 and so on. Is it possible to grant feature that makes them more customizable. For example:

news/2007/09/28    --->  news/2007/09/28/1
news/2007/09/28-0  --->  news/2007/09/28/2
news/2007/09/28-1  --->  news/2007/09/28/3
news/2007/09/28-2  --->  news/2007/09/28/4

Comments

greggles’s picture

Version: 5.x-2.0-beta3 » 6.x-1.x-dev
Status: Active » Postponed

This would require a fair amount of work for little value (in my opinion).

I'd be willing to commit a small patch that can achieve this, but I'm not going to write or test it.

greggles’s picture

Title: Adjustable recurring urls » allow admin to specify

Also, when the first one is entered there's no way for pathauto to know that the second one will come, so are you suggesting that all urls get a "/1" on the end? Or are you suggesting that when the second one comes in the old one gets updated (causing linkrot...)?

That "/1" part of this is one thing that I'm pretty concerned about, so any implementation should be particularly careful in that area (or just not do it).

greggles’s picture

Title: allow admin to specify » allow admin to specify characters to make alias unique

sorry, forgot to finish updating the title

Nilard’s picture

Version: 6.x-1.x-dev » 5.x-2.x-dev

I suppose an option, and when the user checks it, then it is expected that where will be more then one url generated with this template. So the first url becomes /1, second /2 and so one. When the option is unchecked then urls are created the way they are created now.

Dave Reid’s picture

Version: 5.x-2.x-dev » 7.x-1.x-dev

Feature requests for 6.x-2.x only.

nw’s picture

Not sure if this is the right thread for my comment, given the current issue settings! However, here is my 2¢ worth:

I like the idea and see a use for it. As it happens it is possible to configure the separator character in 6.x-1.3 since this value is stored as a Drupal variable. In function in pathauto.inc we have:

<?php
function  pathauto_create_alias() {
.....

// If the alias already exists, generate a new, hopefully unique, variant
  $separator = variable_get('pathauto_separator', '-');
  if (_pathauto_alias_exists($alias, $src, $language)) {
    $original_alias = $alias;
    for ($i = 0; _pathauto_alias_exists(drupal_substr($alias, 0, $maxlength - strlen($i)) . $separator . $i, $src, $language); $i++) {
    }
?>

Using the developer module, I have set the seperator to '/'. However, pathauto is hardcoded to start numbering at 0. It is trivial to patch this for more flexibility. In my dev environment I have:

<?php
function  pathauto_create_alias() {
....
 // If the alias already exists, generate a new, hopefully unique, variant
  $separator = variable_get('pathauto_separator', '-');
  $seq_start = variable_get('pathauto_seq_start', 1);
  if (_pathauto_alias_exists($alias, $src, $language)) {
    $original_alias = $alias;
    for ($i = $seq_start; _pathauto_alias_exists(drupal_substr($alias, 0, $maxlength - strlen($i)) . $separator . $i, $src, $language); $i++) {
    }
?>

Currently this would give item, item/1, item/2, item/3 whereas what I think most users will want item/1, item/2, item/3, item/4

My next goal is to ensure that we can control this. Watch this space.

nw’s picture

I now have a prototype solution to the problem identified by me in #6. What I have done is build in a pseudo-token. What I have for an Automated alias settings is:

item/{seq}

In which case, my modified pathauto module produces aliases item/1, item/2, item/3, item/4 and item/5 for the 5 item nodes I have in my test environment.

What is the best way to disseminate my changes? Attach a patch to this issue? If yes, I'll endeavour to do so ASAP after I figure out how to do it.

Dave Reid’s picture

Title: allow admin to specify characters to make alias unique » Make the 'unique' alias suffixes configurable
Georg’s picture

#328064: Option to add a suffix/extension to aliases, by setting a place for the numbering was merged with this issue and was marked duplicate in favor of this older issue.

porg’s picture

I also would like to control the behavior.
1) I would like to have no dash between the item and number.
2) I would like to start counting with 2. Why? First normal users start counting with 1 rather than 0 (as programmers do), and second, I consider 1 correlates to the first alias which uses the path, and hence the first duplicate starts to get 2.

So did nw's changes from #6 get commited?

I don't see any appropriate configuration possibilities in the 6.x-2.0-alpha3 GUI.
If one wants to control the behavior, must one modify the module's code?
Or write an override function in the template.php ?

iantresman’s picture

Issue summary: View changes

Yes please! It would be nice if I could configure the numeric suffix appended to URL aliases to make them unique, eg, the suffix:

  1. Is placed before existing suffixes, eg. not mydomain.htm-0, but mydomain-0.htm
  2. Could be alphabetical, eg. mydomain-a.htm
  3. That there may be no separator, mydomain0.htm
  4. That the suffix can start at a particular number/letter, eg. mydomain100.htm
  5. That the suffix can optionally be a token, that is used only when a unique URL is required, eg. mydomain-node-id.htm

Option 1 is most important. It could be implemented if there was a "unique suffix token", and I could specify a URL pattern thus:

  • Node: [title-raw][nnnn].htm

In Drupal 6, the current behavior is hardwired in function pathauto_clean_alias in the submodule pathauto.inc.