I have installed the FAQ module on my site, and it defines the path to the FAQ page in code as 'faq-page'. I would like to make the path be 'mypath/faq' instead. I think I need to create a little module that implements hook_menu_alter(), so that if I upgrade the FAQ module, my custom path won't be overwritten. I think it should go something like the following:

* Implements hook_menu_alter.
* Override FAQ page path defined by the FAQ module.
function MYMODULE_menu_alter(&$items) {
  $items['mypath/faq'] = $items['faq-page'];

Is this the proper way for me to override the path defined by another module?

| improve this question | | | | |

No, that's not the right way. You are actually looking for aliases. They are provided by the Path module that is integrated in core.

It's possible to do it the way you propose, but it comes with possible side effects and is a little to much for what you want.

| improve this answer | | | | |

with $items['mypath/faq'] = $items['faq-page']; you basically create an alias for '/faq-page', so you are not overriding anything.
For what you want to achieve is all you have to do.

The unset($items['faq-page']); instruction is unnecessary, use it only if you don't want that the original path will be a valid one and prefer a "page not found" error if some link still happen to point there.

| improve this answer | | | | |
  • I disagree - this may be a way to do it, but it's certainly not the proper way to do it – Clive Jan 30 '14 at 9:35
  • but he is asking the proper way for him. I figured that if he is already developing his own module for other things, he can very well add this one line of code to create an alias as the more effortless way for him to achieve it. making it his proper way. – Astrayus Jan 30 '14 at 12:11
  • I can see merits of both. On the one hand, I had forgotten that I could just add an alias (duh!), because I was thinking that if a URL was defined in code by a module, that I could only override it in code. I didn't want to just modify the module, in the event that a new version was installed, thereby resetting the URL to something that wouldn't coincide with the path in our menu structure. On the other hand, Astrayus is right - I didn't really want the original URL to exist, thinking that the new one would be better for SEO. Is there any harm (SEO-wise) to having more than one path to a page? – eljefejb Jan 30 '14 at 16:29
  • @eljefejb No, as long as you have a proper redirect in place. And then you would probably not link to the original url, would you? – berliner Feb 2 '14 at 15:33
  • Nope, just didn't like the orginal URL. I'm marking your answer as correct. Even though the module only involved a few lines of code, it's easier just to use the alias. – eljefejb Feb 3 '14 at 16:21

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.