重定向或重写 drupal 链接

发布于 2024-09-27 16:39:53 字数 1099 浏览 3 评论 0原文

我有一个用于浏览使用 hook_menu 和视图构建的内容的自定义结构。我希望内容的链接按节点类型路由到我的结构中的适当目的地。因此,虽然通常单击节点链接会将您带到 node/123,但我希望被发送到 foo/123(因为节点 123 的类型为“foo”) )。

我尝试了 PathAuto,但仅将 foo/123 设为 node/123 的别名是行不通的。具体结构、选项卡等...已使用 hook_menufoo/123 构建。 PathAuto(据我所知)实际上只是显示 node/123 这只是普通的 drupal 节点显示,而不是我想要显示的内容。

我开始将 hook_nodeapidrupal_goto 组合在一起,以根据节点类型进行重定向。 [解决一些无限重定向问题,但我确信我能解决。]但是我真的想这样做吗?让网站上的每个链接都通过 HTTP 重定向不会影响速度吗?

最好的方法是什么?

编辑
实际上,我认为问题在于 PathAuto 不尊重我的 hook_menu,并且可能不是适合这项工作的工具。 由于尚未设置 PathAuto,我有一个 hook_menu,它定义了 foo/123 的页面,其中 foo 是节点类型。导航到 foo/### 按预期显示我的自定义版本的节点 ###。

现在我想将 node/### 重定向到 foo/###,或者换句话说,我想要所有链接到 node/###< /code> 写为 foo/###。对于 PathAuto 来说,这似乎是一项显而易见的任务,其中在节点类型 Foo 下,我的模式是 foo/[nid]。除了设置之后,我的 hook_node 不再起作用。这是因为现在 foo/### 正在按照我的要求路由到 node/###,并且显示的是普通的 drupal 节点显示,而不是我的 hook_menu。

I have a custom structure for browsing content built with hook_menu and Views. I would like links to content to be routed by node type to the appropriate destination in my structure. So while normally clicking on a node link takes you to node/123, I instead would like to be sent to foo/123 (because node 123 is of type 'foo').

I tried PathAuto but it doesn't work to just make foo/123 an alias of node/123. Specific structure, tabs, etc... has been built using hook_menu for foo/123. PathAuto (as I understand it) is really just displaying node/123 which is just stock drupal node display, and not what I want to be shown.

I started putting together hook_nodeapi and drupal_goto to redirect based on node type.
[Working out some infinite redirect issues, but I'm sure I can figure it out.] But do I really want to do this? Won't there be a speed hit to have every link on the site pass through an HTTP redirect?

What's the best way to do this?

Edit
Actually I think the problem is that PathAuto isn't respecting my hook_menu, and possibly not the right tool for the job.
With no PathAuto set up yet, I have a hook_menu that defines a page for foo/123 where foo is the node type. Navigating to foo/### works as expected displaying my custom version of node ###.

Now I want to redirect node/### to foo/###, or put another way, I want all links to node/### to be written as foo/###. This seems like an obvious task for PathAuto where under the node type Foo my pattern is foo/[nid]. Except after setting it up, my hook_node no longer functions. That's because now foo/### is being routed to node/### like I asked it to and what's displayed is the vanilla drupal node display, not my hook_menu.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

淤浪 2024-10-04 16:39:53

实际上,可以设置 PathAuto 来指定您的自定义路径类型。它使用令牌模块来允许您轻松地重新配置pathAuto应如何构建别名...

检查pathauto的管理页面(admin/build/path/pathauto)。

编辑

对于您的编辑我要做的是实现 hook_menu_alter,并且我会将 node/% 页面回调修改为 hook_menu 中使用的回调以呈现 foo/123 页面。

Actually PathAuto can be setup to specify your kind of custom path. It uses token module to allow you easily reconfigure how pathAuto should build the aliases...

Check in the administration page of pathauto (admin/build/path/pathauto).

Edit

For your edit What I would do is to implements the hook_menu_alter, and I would modify the node/% page callback to your callback used in hook_menu to render the foo/123 page.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文