I'm not sure if this is already possible, but i have searched about this and did not come up with anything. The feature that I would like to be added is an action for the "Rules" module (similar to the "Create URL alias" action that is generated by the Path module).

The specific scenario that made me want the specific feature is the following:

I have 2 cck fields in my content type Field_Name and Field_ID. The first field (Field_Name) is being used by PathAuto to generate an alias for the node. So the path to the node is:

mysite.com/category/[Field_Name-raw]

However, I have an external application that can only launch links similar to the following:
mysite.com/category/[Field_ID-raw]

so what I'm basically trying to do, is create a redirection from the:
mysite.com/category/[Field_ID-raw]
to
mysite.com/category/[Field_Name-raw]

whenever new content of the specific type is created. However, I cannot find any related action available in Rules.

Can this be added?

Comments

gouky10’s picture

Issue tags: +redirection

i have a problem similar, but in my case i only need to change a number value, i mean

/ruta/*

hacia

/ruta/*/descripcion

if someone has the solution please, help us

Matt G’s picture

Has anyone figured out how to do this?

Here's my situation:

When I create a new node type, the default URL alias is something like:

mydomain.com/questions/51231231/really-long-question-type-that-I-include-for-SEO-reasons

But I also want to make a redirect to something easier to remember, like:

mydomain.com/q/51231231

(And yes, I purposely copied StackOverflow's style for this example!)

So mydomain.com/q/51231231 redirects to mydomain.com/questions/51231231/really-long-question-type-that-I-include-for-SEO-reasons

I'd like to use Rules (or PHP, or some other method) so that when a new node is created, two path redirects are made, instead of only one, which is what happens when you use path redirect/global redirect/pathauto.

Matt G’s picture

Figured it out!

The function in path_redirect.module that actually makes the path redirect is path_redirect_save.
I used this function in my own custom function, that is launched on new node save (using the Rules module).

Here's the scenario:
Let's say you had a cooking website, and a normal URL alias looks like:
domain.com/recipes/400/really-awesome-mac-and-cheese-30-minute-recipe

You use this really long url for SEO reasons. But you also want to automatically make a quicklink or short URL along with it, something like:
domain.com/r/400

In this case, 400 is the node id (nid).

Here's what you should do:
To get that really long URL alias, just use pathauto as normal.

To also make the quicklink/short URL, make a new function and place it in a custom module:

function MODULENAME_make_quicklink($arg0, $nid) {

	// set the shortcut alias
	$quicklink = $arg0 . '/' . $nid;
	
	// set the original drupal node nid link
	$nodelink = "node/$nid";

	// make the path redirect
	$redirect = array(
		'source' => $quicklink,
		'redirect' => $nodelink,
	);
	path_redirect_save($redirect);
}

So if you wanted to automatically make that recipe quicklink, you would make a Rule that on a new recipe node save, execute this PHP code:

$arg0 = 'r'; // because the path is /r/400
MODULENAME_make_quicklink($arg0, $nid) //$nid should be available in Rules by default

Now visiting domain.com/r/400 will redirect to domain.com/node/400, which will redirect to domain.com/recipes/400/really-awesome-mac-and-cheese-30-minute-recipe

Hope this helps anyone searching on Google.
Some keywords: path redirect with rules automatically make new path redirect make new path redirect programmatically with PHP