如何重写特定的 URL?

发布于 2024-08-01 16:42:50 字数 368 浏览 4 评论 0 原文

我想重写以下网址:

  • node/add
  • node/edit 等等

就像 - 内容/添加 - content/edit

我也使用预填充模型,并且希望能够重写此 URL:

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

像这样:

  • content/ add/image?n=48

这可能吗? 如果是这样,我是否需要一些 Drupal 模块,或者我是否必须使用 htaccess 文件?

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?

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

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

发布评论

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

评论(4

∝单色的世界 2024-08-08 16:42:50

使用 pathauto 模块,您可以为您的网址创建别名。 您可以设置很多规则,并且应该能够走得更远。 我不确定它与预填充模型的整合效果如何。 但其余的应该很容易。

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.

鱼忆七猫命九 2024-08-08 16:42:50

您可以使用 hook_menu 创建一个自定义模块来实现这些回调,但这只会创建这些操作的附加 URL 不会删除旧的 URL。

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.

月竹挽风 2024-08-08 16:42:50

查看函数 custom_url_rewrite_inboundcustom_url_rewrite_outbound。 这些不是模块,而是放置在 settings.php 中的函数,它们在低级别上与 drupal 的 url 映射进行交互。

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.

蒲公英的约定 2024-08-08 16:42:50

这里有几个选择。

1)您可以使用pathauto模块重命名路径。 然后,这些路径在服务器级别变得完全可用,但旧的节点/添加和节点/%/编辑路径仍然存在。

2)您可以创建一个通过 hook_menu 实现路径的自定义模块,从 node.module 的 hook_menu 实现中复制适当的代码。 这也会在站点上保留旧的 node/add 和 node/%/edit 路径,但您可以使用 hook_menu_alter 从菜单数组中取消设置适当的路径。

3) 您可以使用 custom_url_rewrite_inboundcustom_url_rewrite_outbound按照Olav的建议运行。

老实说,第一个选择通常是更好的选择,因为它会更快并且不会产生意外的错误。 方法 2 肯定会改变您想要的内容,但也会涉及更改 Drupal 所依赖的一些相当基本的路径,并且当您发现节点模块中未涵盖的角落时,这可能意味着相当多的调试会话。你的改变。 方法 3 我不太熟悉,但看起来它允许您像方法 1 中那样重写路径,但使它们更加真实,但是那里可能潜伏着性能问题,并且需要进行大量的调试。

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.

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