title: How to get rid of `?` in URL when no parameters exist?
body: <p>I have the following rule which checks if the url contains any parameters that start with <code>p2</code>:</p>
  
  <pre><code>function unparse_url($parsed_url) {
    $scheme   = isset($parsed_url['scheme']) ? $parsed_url['scheme'] . '://' : '';
    $host     = isset($parsed_url['host']) ? $parsed_url['host'] : '';
    $port     = isset($parsed_url['port']) ? ':' . $parsed_url['port'] : '';
    $user     = isset($parsed_url['user']) ? $parsed_url['user'] : '';
    $pass     = isset($parsed_url['pass']) ? ':' . $parsed_url['pass']  : '';
    $pass     = ($user || $pass) ? "$pass@" : '';
    $path     = isset($parsed_url['path']) ? $parsed_url['path'] : '';
    $query    = isset($parsed_url['query']) ? '?' . trim($parsed_url['query'], '&amp;') : '';
    $fragment = isset($parsed_url['fragment']) ? '#' . $parsed_url['fragment'] : '';
    return "$scheme$user$pass$host$port$path$query$fragment";
  }
  
  function strip_query($url, $query_to_strip) {
    $parsed = parse_url($url);
    $parsed['query'] = preg_replace('/(^|&amp;)'.$query_to_strip.'[^&amp;]*/', '', $parsed['query']);
    return unparse_url($parsed);
  }
  
  $url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
  
  $new_url = (strip_query($url, 'p2'));
  
  # redirect  if url contains anything that starts with p2 
  
  $filtered = array_filter(array_keys($_GET), function($k) {
      return strpos($k, 'p2') === 0;
  });
  
  if ( !empty($filtered) ) {
      header ("Location: $new_url");
  }
  else {
  
  }
  </code></pre>
  
  <p>If a url contain any <code>p2*</code> parameters, a redirect will be made to the same page without these parameters.</p>
  
  <p>Example:</p>
  
  <p><code>domain.com/?a=3&amp;p2=1</code></p>
  
  <p>will redirect to</p>
  
  <p><code>domain.com/?a=3</code></p>
  
  <p>However, with the current rule, if the original URL is:</p>
  
  <p><code>domain.com/?p2=1</code> </p>
  
  <p>Then it will redirect to:</p>
  
  <p><code>domain.com/?</code></p>
  
  <p>But since it is meaningless, I want that in this case it will redirect to:</p>
  
  <p><code>domain.com/</code></p>
  
  <p>How can it be done?</p>