can pathauto create 2 (or more) aliases to a node at the same time? i am porting a large static site to drupal, and there are numerous cases where a single node needs to be available at 2 distinct url's. simply forwarding to a single canonical url is not adequate.

can pathauto accommodate this? creating a path, modifying the node, then re-submitting to force pathauto to create a 2nd alias would be too time-consuming.

thanks for a great module, and for your help with this...

CommentFileSizeAuthor
#23 multipath.patch9.95 KBsnufkin
#22 multipath.patch9.26 KBsnufkin
#21 multipath.patch10.6 KBsnufkin

Comments

greggles’s picture

Status: Active » Closed (duplicate)

simply forwarding to a single canonical url is not adequate.

Why not? That's what usability experts and SEO folks say is the best thing to do.

See http://drupal.org/node/215785 for more discussion.

isaac77’s picture

Thanks for your response! i agree that _in general_ usability and SEO considerations mean that duplicate content at multiple urls is a bad idea. However, in this case we really do need to have content available at 2 distinct locations. (Won't bore you with the details...)

I may have to work around this by using views to display the nodes, but i would be able to avoid that mess if pathauto could accommodate the creation of multiple paths for 1 node. Let me know if you think there is a way to do this... Thanks again!

isaac77’s picture

Status: Closed (duplicate) » Active
greggles’s picture

Pathauto can't currently do this. I don't plan to add it.

greggles’s picture

Of course, certainly could write code for this, but it would take a lot of campaigning (i.e. other people saying they really need it) for the idea to be committed.

isaac77’s picture

Version: 5.x-2.0 » 6.x-1.x-dev
Category: support » feature

thanks again. i'm moving this 'feature request' for 6.x version.

if anyone else would like to see this functionality, please chime in. of course you're right--if there isn't widespread need for this, no reason to implement.

one note: if duplicate content is not widespread (i.e. the feature i'm asking for is only used on a small proportion of nodes on a site), SEO considerations may not be much of a problem at all.

greggles’s picture

Yes, but...in the post that I marked this a duplicate of I mentioned how this is a problem of usability, SEO, and also the user interface. Setting two aliases per node requires an increasingly complex user interface and Pathauto is already famous for having a "airplane cockpit" of an interface. So, the trick is providing this option without making the interface even more complex.

kenji_kun’s picture

+1 suscribe

In Drupal 6 you can define per language path aliases.
Pathauto this is the next step.

litwol’s picture

Version: 6.x-1.x-dev » 5.x-2.x-dev
Assigned: Unassigned » litwol

greggles,

i will work to do some ajaxy solution where you can click a (+) button and it will make available another input field for you to type aditional pattern. not sure if i'll be able to do this for D5, but i could surely do this for d6.

here is an example of how i do it programaticaly


/**
 * Creates extra path strings for our views
 * 
 */
function _pph_blocks_path_rewrite_product_alias($category) {
  $term_name = pathauto_cleanstring($category->name);
  
  $special_paths = _pph_blocks_special_paths();
  
  $term_name = pathauto_cleanstring($category->name);
  foreach ($special_paths as $index=> $path) {
    $alias_array[$path.'/'. $category->tid] = $path .'/'. $term_name;
  }
	return $alias_array;
}


function _pph_blocks_special_paths() {
  $special_paths = array(
    'products',
    'services',
    'guides',
    'articles',
    'downloads',
  );
  return $special_paths;
}

/**
 * Implementation of hook_taxonomy().
 * this is used to create paths for views
 */
function pph_blocks_taxonomy($op, $type, $array = NULL) {
  switch ($type) {
    case 'term':
      switch ($op) {
        case 'insert':
        case 'update':
          // Use the category info to automatically create an alias
          $category = (object) $array;
          $alias_array = _pph_blocks_path_rewrite_product_alias($category);
      		foreach ($alias_array as $src => $dest) {
    				path_set_alias($src);   //delete the path in case it is already set
      			path_set_alias($src, $dest);
    			}
          break;
        case 'delete':
          //If the category is deleted, remove the path aliases
          $category = (object) $object;
          $alias_array = _pph_blocks_path_rewrite_product_alias($category);
    			foreach ($alias_array as $src => $dest) {
    				path_set_alias($src);   //delete paths
    			}
          break;
        default:
          break;
      }
      break;
    default:
      break;
  }
}

snufkin’s picture

its not just a question of having an extra field for a second (third ...) alias, but rather the ability to assign all the permutations of the given token set.

For example I have a multiselect vocabulary (yellow and red as terms) on a node, and i want the node to be displayed under both terms:

content/[term]/[title]

would result in

content/yellow/[title] and content/red/[title].

This would need some smart automatic alias assigning.

greggles’s picture

@snufkin - that is definitely a related feature, but note that it also requires something like #185446: Provide tokens for each vocabulary (which needs help).

litwol’s picture

i wonder how something like this will be accomplished in d6 menu system? can it be done using menu placeholders ? %?

as for d5 my guess is that there will be a need for something like [map-term] or [loop-term] to tell pathauto or other responsible module to loop through all possible choices of the current term vocabulary or something.

i am just theorizing as i dont have time to spint out any code just yet.

snufkin’s picture

@greggles: thanks for the pointer. Right now we need this feature for a project, so i will work on it, hopefully will result in a working patch.

@litwol: my plan so far (before reading the token issue) was that when $placeholders = pathauto_get_placeholders('node', $node); gets called we create a placeholder array which contains not just single items, but sometimes arrays. This would require adding some smart functionality into pathauto_get_placeholders(), checking the node object, and creating an array out of the terms if necessary.

After this is done in the pathauto_create_alias we would only check if there is a subarray in the $placeholders array, and if there is we loop through that and do the str_replace.

I know this is a very rough plan, I will probably work on this whole day tomorrow, so if you have any tips for how to attack the problem I would be very glad.

oh and we're working on Drupal 5.

snufkin’s picture

im now experimenting with a way of adding a ['term-multi-raw-?'] style token. the values are calculated either in token, or just pluggable from an external module using hook_token_values by checking the $node->taxonomy, and assembling the term path accordingly (for example comma separated list, so i just need to replace it with the '/' separators).

for this to work i still need to make the pathauto aware that if there is a ? in the token settings that means to expect numbers, and proceed accordingly (in my case create multiple paths).

i am not entirely sure if this is the correct approach, but seems sensible since it doesn't involve adding subarrays into the token/values list.

litwol’s picture

how will it handle paths like [vocabulary-multiple-raw-?]/[terms-multiple-raw-?] ?

will this create correct vocab / term hierarchy of paths or ...?

snufkin’s picture

The approach can do that (but im afraid its a bit hackish). the trick is to assemble the path in token using the hook_token_values, and adding the key into pathauto_clean_token_values so your path "/" is not stripped out of the string.

This is (or at least part of it) the code i added

$multi_key = '[term-multi-raw-<questionmarks>]';
  if(strripos($pattern, $multi_key)) { // TODO generalize
    // lets see how many term-multi-raw-<numbers> there are in the tokens
    $multi_tokens = array_filter($placeholders['tokens'], '_fuzzy_search_multi');
    foreach($multi_tokens as $id => $token) {
      $temp_pattern = str_replace($multi_key, $token, $pattern);
      $alias[] = str_replace($placeholders['tokens'], $placeholders['values'], $temp_pattern);
    }
  }
  else { // good old single alias
    $alias[] = str_replace($placeholders['tokens'], $placeholders['values'], $pattern);
  }

And from here on i have to treat $alias as an array. the _fuzzy_search_multi() is just a helper function to cut me out the part from the $placeholders['tokens'] array that i need.

edit weird, php filter things ?]'; is the same as ?>

litwol’s picture

I am not sure, but why do we need the question mark? what is it's purpose?

snufkin’s picture

nothing specific, it just marks that the actual token will have a different ending

litwol’s picture

unless i completely miss the issue at hand (regarding the question mark) i will strongly object against using something as cryptic as that.

snufkin’s picture

thats just a proof of concept kindof thing. There is already something like that, the mod- token:

[mod-????]
All tokens for node creation dates can also be used with with the "mod-" prefix; doing so will use the modification date rather than the creation date.

i will write up a patch soonish, so you can actually see what i meant, maybe this is not the way to go at all.

snufkin’s picture

StatusFileSize
new10.6 KB

so this is my take on this issue, patch against DRUPAL-5--2. It provides a token called [multi-term-path-raw], to be used in configuration when one wants to save the taxonomy hierarchy in the URL, and wants the same node appear under all the subcategories:

example node 3
Taxonomy its filed under:

parent term
`- child term
   `- grandchild term

now for path [multi-term-path-raw]/[nid] this patch generates the following aliases:
<parent term>/3
<parent term>/<child term>/3
<parent term>/<child term>/<grandchild term>/3

The patch is highly experimental, its more like a proof of concept. Normal alias generation might be broken due to the untested nature of this patch.

Two files are changed:
* pathauto.module, in which the token and its value are handled
* pathauto.inc has changes in the alias generation (detects the multi... token in the path and uses a new multiple alias creator function)

snufkin’s picture

Status: Active » Needs review
StatusFileSize
new9.26 KB

Realizing that the actual token definition and value can come from an external module (tested), here is a reroll, without the pathauto.module modification.

snufkin’s picture

StatusFileSize
new9.95 KB

some smaller cleanups, i have so far tested with my module that provides the token, and works just fine, updating aliases works too, however old aliases are not deleted, because I don't know how to differentiate between an automatically created alias and a handmade one.

d.clarke’s picture

I just wanted to chime in and say that the patch snufkin is proposing would be really useful. Early in the thread it appears to be debatable whether the proposed change will be committed... has a decision been made yet?

paganwinter’s picture

+1

asak’s picture

This issue seems stuck.

Another use case: I'm investigating the option of using a single-node product for ubercart, which will serve multiple languages. I'm not going to go into that, and for the sake of this discussion i'll just say i found it to be easier to solve a multilingual ubershop by finding a way for a single node to serve multiple languages then finding a way for multiple product nodes act as a single product as far as ubercart is concerned.

So - say i found a way to display specific content of a node according to the requested language, i still need to have multiple paths, one for every language, to the same node.

This node will also have a title for every language, and it would be best if pathauto could "do-it's-thing" using this language specific info. pathauto integration would mean developing a module which would make pathauto treat every such set of node parts (title, body, cck, etc) as a language, just like it does for language specific nodes, and then pathauto itself would not need to be changed at all.

Just my thoughts... ;)

More info if interested:
http://www.ubercart.org/forum/internationalization/10878/i18n_issues_i_d...
http://drupal.org/project/language_sections (and http://drupal.org/node/313770)

xwalox’s picture

i need to multiple paths for a node, also load it from views depending of term path
how can we build it?

momper’s picture

sub

Jurgen8en’s picture

sub

To be clear, I want to accomplish:

/de/schlusselfinder -> de/node/72
/nl/sleutelvinder-> nl/node/72

Thanks asak, for your reply.

Jurgen8en’s picture

PS. I know, I´m going to do some ugly changements.

First I did the following.
Changed drupal_lookup_path() in path.inc.
To also look after an alias like: nl/sleutelvinder

  //Jurgen8en
  global $locale;

  if ($action == 'wipe') {
    $map = array();
    $no_src = array();
  }
  elseif ($count > 0 && $path != '') {
    if ($action == 'alias') {
      if (isset($map[$path])) {
        return $map[$path];
      }
      //Jurgen8en
      $alias = db_result(db_query("SELECT dst FROM {url_alias} WHERE src = '%s'", $locale."/".$path));
      if(!$alias){
        $alias = db_result(db_query("SELECT dst FROM {url_alias} WHERE src = '%s'", $path));
      }
      $map[$path] = $alias;
      return $alias;
    }

I included the two aliasses:
/de/schlusselfinder -> de/node/72
/nl/sleutelvinder-> nl/node/72

Now, I need to change pathauto to generate these multiple aliasses automaticly.
The title translations comes from some cck-fields.

Jurgen8en’s picture

Executed the latest patch in this issue.

pathauto.module
added some code to function pathauto_token_values($type, $object = NULL) {

          $label = 'term';
	  
	  //Jurgen8en
          $langaliasses = array();
          foreach (array_keys(i18n_supported_languages()) as $lang){
	    $title = $object->title;
	    if($lang != 'nl'){
		    $title = db_result(db_query('SELECT field_title_'.$lang.'_value FROM {content_type_'.$object->type.'} WHERE nid = %d', $object->nid));
		    if(empty($title)){
			    $title = $object->title;
		    }
	    }
            $langaliasses[] = '/'. $lang.'/'. $title; // stack the levels
          }
          $values['multi-term-path-raw'] .= implode(';', $langaliasses);
          // keeping the path-raw ending so pathauto_clean_token_values() doesn't filter / out
          // using ; as a separator for the different entries, so we can handle it as an array
          // in the search and replace phase

        case 'taxonomy':

This generates:
/de/schlusselfinder -> node/72
/nl/sleutelvinder-> node/72

dave reid’s picture

Status: Needs review » Closed (won't fix)

Ack I don't think we should be displaying multiple path fields for users. This is horrible for usability, module complexity, and best practices.. Users should understand it's best to have one path to a node. I do however support adding a table listing all the aliases pointing to a node. Maintainers are completely free to override me on this, but I just don't see this happening.

See
http://drupal.org/project/showaliases
#645894: Combine with Pathauto

Jurgen8en’s picture

Read my previous posts (remember this is a horrible solution)
Updated code of
function pathauto_token_values($type, $object = NULL) {

//Jurgen8en
          $langaliasses = array();
          foreach (array_keys(i18n_supported_languages()) as $lang){
	    $title = '';
	    if($lang == 'nl'){
		    $title = db_result(db_query('SELECT title FROM {node} WHERE nid = %d', $object->nid));
	    }else{
		    $title = db_result(db_query('SELECT field_title_'.$lang.'_value FROM {content_type_'.$object->type.'} WHERE nid = %d', $object->nid));
	    }
	    if(!empty($title)){
                    $langaliasses[] = '/'. $lang.'/'. $title; // stack the levels
	    }
          }
          $values['multi-term-path-raw'] .= implode(';', $langaliasses);
          // keeping the path-raw ending so pathauto_clean_token_values() doesn't filter / out
          // using ; as a separator for the different entries, so we can handle it as an array
          // in the search and replace phase

        case 'taxonomy':
hnln’s picture

subscribe,

looking for a way to have single node (no language) have different aliasses for each language. For example when having an image content type, in dutch I want them to be available by beelden/[title] and in english images/[title].

momper’s picture

@HnLn

i'm looking for the same - do you know, if is there another issue for this? or should we open one?

greetings momper

isaachorton’s picture

Version: 5.x-2.x-dev » 6.x-1.4
Priority: Normal » Critical
Status: Closed (won't fix) » Active

EDIT - I'm using pathauto 6.x.1.4
Has anyone solved this?

I have a desperate need to associate multiple aliases to single nodes of content.

In my case I have a content type called press_release. I want to be able to create a single press release node with a menu link in primary links to:
/company/press-releases/press-release-title

However I also want the following aliases to work:
/section1/press-releases/press-release-title
/section2/press-releases/press-release-title

What I would like to accomplish would be to add a single press-release and have the additional path aliases created. so that each section acts as a complete mirror of the content.
The listing page for each press releases section are required to be section-dependent so that they link to the particular section's single press release(node).

there is a usability confusion issue which is why I need the duplicate content.

I havent found the solution yet that makes sense to me. Something that goes in template.php maybe?

Anyone have a suggestion?

greggles’s picture

Title: need multiple paths for one node... » Multiple patterns/paths for one entity
Version: 6.x-1.4 » 7.x-1.x-dev
Assigned: litwol » Unassigned
Priority: Critical » Normal
Status: Active » Postponed

There is some work in Pathauto for 7.x that would allow us to do this without making the UI hell, but until that happens this issue is postponed. #273104: Using "progressive disclosure" for alias patterns.

dave reid’s picture

Um, I thought we were *never* going to support more than one alias per path in pathauto? Hence the won't fix. We can make it possible for that to happen, but it's not pathauto's place to encourage it.

greggles’s picture

Yeah, I was mostly ready to go back to "won't fix" but I feel like we can consider it with the new UI.

My major complaint is that it makes the UI horrible. If people want to mess up their SEO..so be it.

dave reid’s picture

I still don't think it's really possible with the UI I have planned. It's just going to complicate things way too much.

jerrac’s picture

I'm currently working on a project that would benefit greatly from this feature.

So, I'm subscribing...

dave reid’s picture

Status: Postponed » Closed (won't fix)

I'm going to go ahead and mark this won't fix because we shouldn't be supporting this in Pathauto.

solide-echt’s picture

Just stumbled upon this thread.

IMHO a better approach to have multiple url's access a single node is to build a view that displays the node and provide arguments in the view that are used in the path. With this approach you can obscure the "real" path of the node from the user. It should also be possible to provide a canonical url for the node, hence SEO should be kept intact.

momper’s picture

+1

yngens’s picture

Status: Closed (won't fix) » Active

Here is quite legitimate use case. I'm trying to sep up a dictionary site on Drupal and need to make some nodes to be accessible by different forms of the words. Like it is done on dictionary.com. For example, all the following urls point to the same content:

http://dictionary.reference.com/browse/compute
http://dictionary.reference.com/browse/computable
http://dictionary.reference.com/browse/computably
http://dictionary.reference.com/browse/computability
http://dictionary.reference.com/browse/computist

Only top part changes, however they all go to http://dictionary.reference.com/browse/compute
Would be nice if pathauto left the number of possible aliases per node to the user. I believe CEO consideration should not limit very logical development path for this excellent module.

greggles’s picture

Status: Active » Closed (won't fix)

Maybe it's a legitimate case for you, but Pathauto will not do it in the near term. It would create UI complexity that would benefit a small group and harm a large group.

jerrac’s picture

Sounds like it might be a good idea to make a separate module that adds the functionality to Pathauto.

*adds idea to list of things to look into*

yngens’s picture

Project: Pathauto » Drupal core
Version: 7.x-1.x-dev » 7.x-dev
Component: Miscellaneous » path.module

It has just came to my mind that for URL path settings on node edit page is responsible the core path module, not pathauto module. So transferring this issue to the core to request a new feature for the path module.

Is it possible for path module to provide definite or limitless number of fields for setting path aliases per node?

Considering that it is possible to add indefinite number of aliases through the module's administration page, why not to provide the same functionality through UI on node edit?

yngens’s picture

Status: Closed (won't fix) » Active

Forgot to make the issue active for the core path module.

greggles’s picture

Project: Drupal core » Pathauto
Version: 7.x-dev » 7.x-1.x-dev
Component: path.module » Miscellaneous
Status: Active » Closed (won't fix)

Please open a new issue for that.

It should be against Drupal 8.

yngens’s picture

I did. Interested, please, follow http://drupal.org/node/1023804

owntheweb’s picture

Chiming in. I apologize as this turned into a novel...

I'm working on a large site, combining what used to be a lot of separate floaty websites under the same organization roof.

While merging, each program section is still quite large, has it's own sub-theme and for user convenience a media section is available for each program with news and such for that specific program. At the base level a master media section covers media for all programs (the "home" of all media contents).

Sitemap preview (program media sections circled, main media section in bold red):
http://www.flickr.com/photos/8139783@N08/5998496542/

If users jump from program media views to the main media section to view a node, the sub-theme and program navigation gets lost. It has a jolting effect on the user experience.

Personal gut feeling: Only have one alias and users can deal with the theme/nav jolt. - I could add a back link at the top and bottom of the post to soften the blow. SEO rules.

Customer oriented feeling: Offer added aliases for program media sections to keep nav and theme intact when viewing nodes (theme, blocks, etc. based on consistent structured aliases) - maybe I could add a noindex tag for those aliases?

Possible solution: I could create a "multipath" module (got the idea after watching the 5th Element - "multipass!"). It would manage multiple aliases (still working out how to go about this for general public use) and place noindex metatags on the non-pathauto aliases. I don't see my solution as being included in pathauto as it seems so custom-need.

What are your thoughts?

Thanks for the feedback. :)

greggles’s picture

If you need to do this I suggest you depend on Pathauto and leverage it's functions.

I built a similar site last year and we used the user's session to control the theme. The PURL module is also meant to provide that kind of feature without requiring multiple Drupal aliases (though it does have the multiple urls = bad for SEO drawback).

owntheweb’s picture

greggles,
I like the user session variable idea. I guess I could reset a "program" session variable when visiting media listing pages (e.g. news briefs, press releases, photo galleries, videos and similar main media categories). That way if someone visits the Research and Analysis News Briefs page, clicking on an article would keep the URL SEO happy and theme/nav elements intact somehow.

I noticed on the PURL project page mentioned maintaining info using session variables like this is "hackish". Is that a bad thing? :)

phponwebsites’s picture

I want to access page content/article-title/value1, content/article-title/value2 and content/article-title. Is it possible? If yes, the how can do this?

NirmalaGuru’s picture

Issue summary: View changes

recently I came across a task in my application, Where i had to select taxonomy terms as checkbox and i had to create multiple url aliases with all the taxonomy term name on submission of node,like term_name1/title, term_name2/, term_name3/title.... here is the code which helped me, hope it helps others too....

<?php
function multiplealiases_node_insert($node) {
  $source = 'node/'.$node->nid;
  $type = $node->type; 
  switch($type) {
    case 'types_of_products':
    // Update alias for types_of_products content type on the basis of multiple types selected. We are using field_manual_product checkboxes as term reference and on the basis of this these types we create same number of url alias. 
      if(module_load_include('inc','pathauto','pathauto') !== FALSE) {
        if (function_exists('pathauto_cleanstring')) {
          $currnt_page_title_alias = pathauto_cleanstring($node->title); // define in pathauto.inc file.
        } else {
          $title =  strtolower($node->title);
          $title =  str_replace('&','',strtolower($title));
          $title =  str_replace(' ','-',strtolower($title));
          $title =  str_replace('--','-',strtolower($title));
          $currnt_page_title_alias = $title; 
        }
      }
	 
      $selected_programs =  $node->field_manual_product['und']; 
      db_delete('url_alias')
         ->condition('source', $source)
        ->execute();
		$i=0;
      foreach($selected_programs as $selected) {
		  
		$id = $node->field_manual_product[und][$i][tid];
		//field_manual_product are the term references and each one of them has term field called field_types_of_products
		$term = taxonomy_term_load($id);
		$name = $term->name;
		$actual_prodname = $term->field_types_of_products[und][0][value];
		$i++;
        $selected_programs_nid = $selected["value"];
		// field_types_of_products is my term field as type of the field 
        $newsAlias = $actual_prodname.'/'.$currnt_page_title_alias;
        // check if url exist
        $newsAlias =  get_multiple_url_alias($newsAlias);    
		drupal_set_message($newsAlias);
        if(!empty($newsAlias)) {    
          db_insert('url_alias')
            ->fields(array(
            'source' => 'node/'.$node->nid,
            'alias' => $newsAlias,
            'language' => 'en',
          ))
          ->execute();
        }
      }    

    break;
	
	default : print "no case matching";
	break;
  }    
}
function get_multiple_url_alias($custom_alias){
  $i = 0;
  do {
    if($i==0){ 
      $newAlias = $custom_alias;
      $query = db_query("SELECT pid FROM url_alias WHERE alias =:alias", array(':alias'=>$newAlias));
    }else{
      $newAlias =  $custom_alias."-".$i;
      $query = db_query("SELECT pid FROM url_alias WHERE alias =:alias", array(':alias'=>$newAlias));
    }
    if ($query->rowCount() == 0) {
      break;
    }
    $i++;
  } while ($i > 0);
  return $newAlias;
}
?>
phponwebsites’s picture

Finally, I got the solution for set up multiple path alias for a node in drupal 7 using pathauto module. Please visit http://www.phponwebsites.com/2016/08/drupal-7-pathauto-multiple-url-alia....

It will be helpful.