-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

1

1 Answer 1

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.

3
  • So, I was able to use this module: drupal.org/project/match_redirect. Its works in the sense that it redirects properly, with wildcards, but the problem being my use case just changed. So, now I need to have the following URL: mysite.com/sem-one-two/play and redirect to mysite2.com/sem-one-two/play Commented Mar 24, 2014 at 23:26
  • If you want Drupal to get involved, drupal_goto() can take a full URL; I would instead look to some sort of webserver/.htaccess redirect instead if it needs to go to a different server
    – Jimajamma
    Commented Mar 24, 2014 at 23:32
  • Let me restate..., I will edit the original post. Commented Mar 24, 2014 at 23:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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