For SEO purpose, I need to use hyphens instead of slashes in a URL defined in hook_menu, here's an example :

$items['mypath-%'] = array(
  'page callback' => 'mypath_render',
  'page arguments' => array(1),
  'access callback' => TRUE,
  'access arguments' => array('access_content'),

Apparently Drupal doesn't support it natively. Is there a way to make it work ?


1 Answer 1


Although I would never do this just for the sake of SEO personally, I believe the workaround is to use both hook_url_inbound_alter() and hook_url_outbound_alter(). By using these hooks you can change any URL displayed by the site to replace slashes with the hyphen, and then back again when Drupal processes the page after the user has clicked the URL. That way you can still use slashes in your hook_menu(), but it would show as hyphens in your site.

I'm not sure there is any other way.

Oh dear, I just realised the question was for Drupal 6, my apologies.

I think for Drupal 6, using custom_url_rewrite_inbound() and custom_url_rewrite_outbound() could be used instead.

  • I'm working on a site which use hyphen-only URLs so I don't really have a choice. Anyway, I'm gonna give it a try and see if it works ! Thanks a lot. Dec 4, 2012 at 12:43
  • I've done a similar thing using Drupal 7 and it works well. Not tried it with those Drupal 6 functions but they should do the same thing, though they are not hooks, so they should go in the settings.php file. Good luck. Dec 4, 2012 at 12:49
  • Works like a charm, I thank you dearly for the time you made me save by not having to dive into the depths of the Drupal API. Dec 4, 2012 at 13:31

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.