1

I needed to create a custom module to show product information. It's a custom module because the data comes from a remote database. This module has a block which I add to a basic page. (It was my first drupal website from some time ago, and I know it's not the conventional method.)

Now in this module I do a $_get call from a product id in the url. For example if the page is /product?id=50, it will get the product of id 50 and show that information in the block. Now at request of the client the url needs to look like /product/50 for SEO reasons. Also true for categories for example categories/boots instead of categories/category=boots

I tried using http access file but I can't get it to work. Also see: Drupal does rewrite url but can't load css/themes

Now they suggested to use Pathauto module. So I've installed the module. But it won't create those url's taking the custom variables into account. Is there a way so I make Pathauto take into account those extra variables needed for my $_get? Or is there a better method?

I've never used this module before, so noob proof advise is appreciated.

0

You have a 2-step problem.

1) User friendly URLs

Pathauto is the wrong solution. Setting URLs in custom modules is the job of hook_menu.

function mymodule_menu() {
  $items['product'] = array(
    'page callback' => 'mymodule_product_view',
  );
  return $items;
}

function mymodule_product_view($id = 0) {
  //Do database call here for product id = $id
}

Using this simple example, you can visit the page product/50. Drupal will then call the mymodule_product_view function with the second parameter (in this case 50) as the arguement.

2) Creating a block to show product information

What you need to get is the product name or id. If that is already in the url you can use arg(2) assuming your URL is "examples.com/product/50". Here is the api page for Drupals arg function.

Ideally you would then do database calls etc. with this arguement within a custom modules block. You can find out how to create a block in custom code here

0

To solve my problem I've written a custom module with the hooks url inbound and outbound

(https://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_url_inbound_alter/7)

This worked for me. I still don't know why the .htaccess approach didn't work tough.

  • Could you please share your code has an example ? – anou Nov 20 '14 at 14:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.