Hello,
I rewrite a url of one of my nodes to improve the referencing in the pagination.
Example of original pagination:
node/75?page=2
I would like this same url becomes:
node/75-p2
Is it possible to do this with Drupal? Like this, I tried but it does not work:
function custom_url_rewrite_outbound(&$path, &$options, $original_path) {
global $node;
global $user;
if (preg_match('|^node/([0-9])?page=([0-9])|', $path, $matches)) {
$path = 'node/' . $matches[1] . '-p' . $matches[2];
}
}
Thank you for your help!
-------EDIT-------
I just found the solution (for myself !!!).
Here's the code for what it might be of interest: (pagination works with all pages of Drupal (node, views, etc..))
In template.tpl.php
function custom_url_rewrite_outbound(&$path, &$options, $original_path) {
//global $node;
//global $user;
parse_str($options['query'], $query); //Met dans un tableau les queries de l'url
if ($query['page'] != NULL)
{
$path = $path . '-p' . $query['page'];// Chemin normal (alias d'url) + pagination rajoutée
unset($query['page']);// Efface l'élément du tableau contenant la paginaiton
$options['query'] = http_build_query($query, '', '&'); //Met le tableau dans la variable (remet dans le bon sens par rapport à la transformation juste avant)
}
}
In .htaccess