如何在drupal中使用通配符
我有一个由 drupal 管理内容的网站,但另一个应用程序处理电子商务(我的客户不喜欢更改他自己的电子商务)
我不喜欢让电子商务看起来与其他网站不同,所以我用主体中的 php 代码创建了一个 drupal 页面节点,它只包含外部应用程序并对其进行初始化。
它运行良好,但问题是电子商务生成的另一个链接:
http://example.com/shop #The Page node i've created, this work
http://example.com/shop/catalog/fruit/ #here comes the trouble!
外部应用程序自行处理网址,所以我需要告诉 drupal 重定向所有以 shop
到他的 shop
页面节点...类似
http://example.com/shop/* => load http://example.com/shop
这样做的最佳实践是什么?
I have a website where drupal manage the contents, but another application handle the e-commerce (my customer doesnt like to change his own e-commerce)
I dont like to have the e-commerce to looks differently from the rest of the websites, so i've made a drupal Page node with php code in the body, that simply include the external app and initialize it.
It works well, but the problem is the other link the e-commerce generate:
http://example.com/shop #The Page node i've created, this work
http://example.com/shop/catalog/fruit/ #here comes the trouble!
The external app handle the url by its own, so what i need is to tell drupal to redirect all the url that begin with shop
to his shop
Page node... something like
http://example.com/shop/* => load http://example.com/shop
What is the best practices to do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您创建一个模块而不是一个节点,这将非常容易。
使用 hook_menu() 来匹配 URL 字符串
创建带有钩子菜单的回调允许您调用自己的代码,回调返回的值会显示在页面中。当 drupal 看到与 shop* 匹配的 URL 时,它将调用函数 example_callback。在此函数中,您可以将当前的代码放入页面节点中。并返回您希望在页面中显示的内容。
If you create a module rather than a node this will be quite easy.
use hook_menu() to match the URL string
Creating a callback with hook menu allows you to call your own code, the value returned by the callback will be displayed in the page. When drupal sees a URL which matches shop* it will call the function example_callback. In this function you can put the code you currently have in your page node. And return the content you wish to display in the page.
经过谷歌搜索后,我发现 Drupal custom_url_rewrite_inbound 正是我所需要的。
我将该函数插入到我的 /sites/default/settings.php 中:
它就像一个魅力!
After googlin around, i found the Drupal custom_url_rewrite_inbound that does exactly what i need.
I inserted the function in my /sites/default/settings.php:
It works like a charm!