How to create pathauto same stackoverflow.com

758 views Asked by At

I know that stackoverflow.com uses the module pathauto. I would like to use pathauto in drupal to create pathauto uris. But I don't know how to do this.

Example: domain.com/node/1 after using pathauto then domain.com/article/1/title-node

Now I want to go to domain.com/article/1/??? then still it shows node 1 instead of show page not found.

4

There are 4 answers

1
Andrew On

I am going on the assumption that what you want to do is have an url structure like http://example.com/article/ID/title where the title part is pretty much ignored and it will go to http://example.com/article/ID no matter what is entered for title. What you could do is set up a view that has the path http://example.com/article which accepts ID as an argument which is used to specify an individual article - most likely by the nid. It should then ignore anything that comes after it.

0
Joey On

You can't do that with pathauto since all it does is creating aliases for your URLs. So you have to use an URL like http://example.com/article/1/title exactly as it was generated.

Stack Overflow goes a slightly different way in the sense that they simply ignore whatever comes as question title in the URL. They can do that since the URL parser is entirely different. For Drupal you may want to look for another module or roll your own. Pathauto just taps into the normal URL aliases and auto-generates them for you. No more, no less.

A search for modules which deal with URLs on drupal.org yields quite a few matches. Some of them might do what you want.

3
mac On

EDIT - I got a better idea

I'm leaving my original answer below, but I think I got a better idea... you could implement hook_init() in a custom module of yours or custom_url_rewrite_inbound() in settings.php in order to strip your page request of the hyphened part, so that the url /article/1/my-title gets changed to /article/1 all the times. The alias from node/XXX to article/XXX would still be done by pathauto.

My original answer was:

I don't know if there is a module that already does that, but achieve what you want is quite easy. You should implement your own version of hook_menu() defining the function that will be triggered by an URL starting with "article" (for example "article/1/title-node").

For hook_menu, each bit separated by a slash is an argument that can be passed to the callback, so you will want to pass to the callback the number (so that the callback will load the proper node) and discard everything else.

Assuming you are using Drupal 6 Your menu item definition should look something like:

$item['article'] = array(
  'title' => 'My URL article redirect',
  'page callback' => 'name_of_my_callback_function',
  'page arguments' => array(1), //this passess the second bit of the URL
  'type' => MENU_CALLBACK,
);

Hope this helps!

0
Capi Etheriel On

have you tried global redirect, which ensures you only see the aliased path? http://drupal.org/project/globalredirect and what about subpath alias? it allows you to use alias as subpaths also. for example, say node/1 alias is blog/johndoe/my-first-post , you could edit it using blog/johndoe/my-first-post/edit http://drupal.org/project/subpath_alias

i guess you can work with these modules.