-1

I am having problems with a sort of pattern matching or path parsing issue.

If I have the following URL: http://www.mysite.com/sem-one-two/play

I have an application that runs at /play, which is not within Drupal.

What I want to do is take URLs, like the above, and pass them to the app.

So in this case, an SEM add links here: http://www.mysite.com/sem-one-two/play

Basically, I want to make the 'sem-one-two' mean nothing in Drupal, but pass it along to the app. In the module Match Redirect (https://drupal.org/project/match_redirect), Im able to take any URL, like above, and redirect to '/play'. Which gets me half-way, but I need Drupal to ignore 'sem-one-two' if it ends in '/play', but still pass it along to the app.

Am I making any sense? Is there anyone out there that understands what Im asking and has any ideas?

thanks, Mac

0

A couple of ways to look at this in a custom module:

With hook_init() you should be able to do something like this:

function YOURMODULE_init() {

  if (arg(1)=='play') {  //  arg(0) is equal to sem-one-two, arg(1) is equal to play, in your example anyway
    drupal_goto('play');
  }

}

but this doesn't take into account any caching of pages for anonymous users so I really don't know how it might work in the real world but if you don't care about the first argument, it should be ok. (hook_boot() is run for anonymous users/cached pages but does leave out edge caches such as Varnish etc)

What you most probably IMHO should do is something with hook_menu(), eg set up something like this:

function YOURMODULE_menu() {

  array $items;

  $items['your-module/%/play'] = array(
    'title' => 'Play',
    'page callback' => 'yourmodule_play',
    'page arguments' => array(1),
    'access callback' => TRUE,
  );

  return $items;

}

along with:

function yourmodule_play($what) {

  // do whatever with $what...

}

This way, you have one menu callback for everything your module wants to "play" plus you know what the "two words" are you are dealing with.

Note that in this second example, it is prefaced with your-module as I really haven't seen (and personally think it to be in poor form to have) the first argument in a Drupal path to be itself a wildcard.

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.