How to use wildcards in drupal

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?

Answers


If you create a module rather than a node this will be quite easy.

use hook_menu() to match the URL string

function example_menu() {
  $menu = array()
  $menu['shop'] = array(
  'page callback' = 'example_callback';
  )
}

function example_callback() {
  // use arg() to get arguments.
  return shop_php();
}

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.


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:

function custom_url_rewrite_inbound(&$result, $path, $path_language) {
  if(preg_match("/^shop(\/)/", $path, $matches)) {
    $result = 'node/XX'; //XX is the ID of my Page Node with the ecommerce code.
  }
}

It works like a charm!


Need Your Help

Angular $watch event isn't firing on change in window.getSelection().anchorNode

angularjs highlight intervals watch

I watch for changes in user highlighted text. I trigger base on DOM element being highlighted. I have the following function:

How to selected week in calendar in zk

java javascript zk

how to selected whole week in calendar on onclick on Calendar component. Just like this image.