views:

43

answers:

2

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?

A: 

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.

Jeremy French
I dont understand how this will help me, can you provide more details?I dont need just to load the drupal menu, but the entire page (blocks, views, menus, etc..) with an external content.
DaNieL
have updated answer
Jeremy French
Sorry, i dont like to create a module just for that.Take a look at my own answer.
DaNieL
+1  A: 

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!

DaNieL