Add url alias with parameter (?foo=bar) I need to create urls aliases like this:

/mypath?foo=bar&amp;foo2=bar2 (source) -&gt; /foo/bar (alias)


via standard drupal alias url add (admin/config/search/path), but when I insert that link in the source path textfield I receive an error about not existent source path. But the path is correct (it works).

How can I resolve it? Only via direct db query?
The reason you get that error is that the form validation handler verifies the source entered in the form is a valid menu path, using drupal_valid_path().

Setting the path alias directly in the database would cause errors, as the source of the path alias is used to set $GET['q'], in drupal_path_initialize(), which contains the following code.

$_GET['q'] = drupal_get_normal_path($_GET['q']);


In your case, $_GET['q'] would be set to mypath?foo=bar&amp;foo2=bar2. All the functions that use $_GET['q'] expect it to the in  the format path/subpath; the presence of the query parameters would cause errors. See for example the code executed by menu_get_item().

Using a custom module, you could implement hook_url_inbound_alter(), and hook_url_outbound_alter(). The first would transform foo/bar in mypath, setting $_GET['foo'] = 'bar', and $_GET['foo2'] = 'bar2'; the second would transform mypath in foo/bar, when $_GET['foo'] == 'bar', and $_GET['foo2'] == 'bar2'.