0

I use hook_url_outbound_alter to change my url to /q=anything, but the url in browser is shown as /q%3Danything. How can I avoid that Drupal encodes the url?

Other choice would be to send q=anything as query, but then hook_url_outbound_alter includes the "?" character, and I can't include it.

if (preg_match('|^search/node/(.*)|', $path, $matches)) {
  $path = 'q=' . $matches[1];
}

Any idea? Thanks in advance.

0

3 Answers 3

1

you shouldn't need to add the "q=" drupal will deal with that side of things, especially when you turn on clean urls.

1
  • I use clean urls, but I need that search url be "/q=anything". As I said, with $options['query'] Drupal set url to "/?q=anything", but introduce "?".
    – Pedro
    Aug 5, 2013 at 16:40
0

If you want to add ?q=anything to the path you should add your query as an option to the $options array.

if (preg_match('|^search/node/(.*)|', $path, $matches)) {
  $options['query'] => array('q' => 'anything');
}
2
  • But if I add ?q=anything with $options, how do I remove the character "?" from the path?
    – Pedro
    Aug 6, 2013 at 6:36
  • /q=test is not a valid URL. The = character is something that tells the value of a query (?). Aug 6, 2013 at 8:19
0

You cannot get a path like q=anything without encoding the equal sign; that is done to avoid problems with a path like q=anything?parameter=value. Your alternatives are just two:

  • Get the question mark before the q doing as Pontus Nilsson said
  • Avoid using q=anything, and use q/anything

The latter is what Drupal normally does. In fact, the path for a node is node/node-id, not node=node-id; the path for a user profile is user/user-id, not user=user-id.

Keep in mind that a clean path like node/1 is translated to index.php?q=node/1 in the .htaccess file. In your case, q=anything would be translated to index.php?q=q=anything. That is the reason why the second equal sign needs to be encoded.

1
  • This question is due to that SEO people need to change the usual path of search "search/node/anything" to "q=anything", and it is getting harder than I thought.
    – Pedro
    Aug 6, 2013 at 8:45

Your Answer

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

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