我知道 stackoverflow.com 使用模块 pathauto。我想在 drupal 中使用 pathauto 来创建 pathauto uri。但我不知道该怎么做。
示例:使用 pathauto 后domain.com/node/1然后domain.com/article/1/title-node
现在我想去domain.com/article/1/??? 然后它仍然显示节点 1 而不是显示未找到的页面。
编辑 - 我有一个更好的主意
我将在下面留下我原来的答案,但我想我有一个更好的主意......你可以hook_init()
在你的自定义模块或custom_url_rewrite_inbound()
settings.php 中实现,以去除你的连字符部分的页面请求,以便 url/article/1/my-title
被更改为/article/1
所有时间。从 node/XXX 到 article/XXX 的别名仍然由 pathauto 完成。
我原来的答案是:
我不知道是否有一个模块已经做到了,但是实现你想要的很容易。您应该实现自己的版本来hook_menu()
定义将由以“article”开头的 URL 触发的函数(例如“article/1/title-node”)。
对于 hook_menu,由斜线分隔的每个位都是可以传递给回调的参数,因此您需要将数字传递给回调(以便回调将加载正确的节点)并丢弃其他所有内容。
假设您使用的是 Drupal 6,您的菜单项定义应类似于:
$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,
);
希望这可以帮助!
你不能用 pathauto 做到这一点,因为它所做的只是为你的 URL 创建别名。所以你必须使用像http://example.com/article/1/title这样的 URL,就像它生成的一样。
Stack Overflow 的方式略有不同,他们只是忽略了 URL 中的问题标题。他们可以这样做,因为 URL 解析器完全不同。对于 Drupal,您可能想要寻找另一个模块或推出自己的模块。Pathauto 只是利用正常的 URL 别名并为您自动生成它们。不多也不少。
在drupal.org 上搜索处理 URL 的模块会产生很多匹配项。他们中的一些人可能会做你想做的事。
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.
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.