views:

172

answers:

4

I want to rewrite the following urls:

  • node/add
  • node/edit etc

To be something like - content/add - content/edit

I also use the prepopulation model, and would love to able to rewrite this URL:

  • node/add/single-gallery-image?edit[field_gallery_node_reference][0][nid]=48

To something like this:

  • content/add/image?n=48

Is this possible? If so, do I need some Drupal module for this, or will I have to take on the htaccess file?

A: 

You could create a custom module that implements these callbacks using hook_menu, but this would just create additional urls for these actions not remove the old ones.

Jeremy French
+5  A: 

With the pathauto module you are able create aliases for your urls. You can setup a lot of rules and should be able to get quite far with it. I'm not certain how well it integrates with the prepopulation model. But the rest should be quite easy.

googletorp
Not exactly what I wanted. I want the URLs to change at a server level. So that the long link can be called using the other syntax. Does that make sense?
RD
A: 

Have a look at functions custom_url_rewrite_inbound and custom_url_rewrite_outbound. These are not modules but functions placed in settings.php that interface with drupal's url mapping on a low level.

Olav
+1  A: 

There's a couple of options here.

1) You can use pathauto module to rename the paths. These paths then become perfectly useable at the server level, but the old node/add and node/%/edit paths would still exist.

2) You can make a custom module which implements the paths via hook_menu, copying the appropriate code out of node.module's hook_menu implementation. This also would leave the old node/add and node/%/edit paths on the site, but you could then use hook_menu_alter to unset the appropriate paths from the menu array.

3) You can use the custom_url_rewrite_inbound and custom_url_rewrite_outbound functions as Olav suggested.

Honestly, the first option is generally the better one, as it will be faster and not open up unexpected bugs. Method 2 will definitely change what you want, but will also involve changing some fairly basic paths that Drupal depends on, and it's possible that this will mean quite a lot of debugging sessions as you discover corners of the node module that weren't covered in your changes. Method 3 I'm not as familiar with, but it looks like it allows you to rewrite paths as in 1, but make them more real, but there's possible problems with performance lurking there, and again, a good amount of debugging to do.

John Fiala