In my site clean urls is not working. As a result ?q is getting appended to the url.

My site url is http://abc.com/?q=user

I wrote a form in a page, and redirect to another view which is http://abc.com/?q=listings.

When I click on submit button in form page GET parameter are not getting appended correctly: They are getting appended as http://abc.com/?field_list=3 which has to be like this http://abc.com/?q=listings&field_list=3. I must use GET method in the form.

How should I redirect to URLs that contains "?q="?

How to do this.

1 Answer 1


If you are redirecting from the form submission handler, you need to use code similar to the following one.

$form_state['redirect'] = array(
     'query' => array(
     'field_list' => '3',

That code is equivalent to calling drupal_goto('listings, array('query' => array('field_list' => '3')) which should never be used inside a form submission handler. In both the cases, the function that is called to build the URL is url(), which works when clean URLs are enabled, or not.

  // With Clean URLs.
  if (!empty($GLOBALS['conf']['clean_url'])) {
    $path = drupal_encode_path($prefix . $path);
    if ($options['query']) {
      return $base . $path . '?' . drupal_http_build_query($options['query']) . $options['fragment'];
    else {
      return $base . $path . $options['fragment'];
  // Without Clean URLs.
  else {
    $path = $prefix . $path;
    $query = array();
    if (!empty($path)) {
      $query['q'] = $path;
    if ($options['query']) {
      // We do not use array_merge() here to prevent overriding $path via query
      // parameters.
      $query += $options['query'];
    $query = $query ? ('?' . drupal_http_build_query($query)) : '';
    $script = isset($options['script']) ? $options['script'] : '';
    return $base . $script . $query . $options['fragment'];

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.