title: PHP htaccess Redirect url with query string from uppercase to lowercase
body: <p>I have this small php script and couple lines in htaccess to redirect urls with query strings from uppercase to lowercase.</p>
  
  <p>However, it redirects uppercase characters in query string to lowercase ones only if there is an uppercase character in the url file or directory part of the url.</p>
  
  <p><strong>Example with uppercase directory:</strong></p>
  
  <pre><code>domain.com/JOBS/?position=Java+Developer
  </code></pre>
  
  <p>will be redirected to</p>
  
  <pre><code>domain.com/jobs/?position=java+developer
  </code></pre>
  
  <p><strong>Example with no uppercase in directory or file name, but only in query string:</strong></p>
  
  <pre><code>domain.com/jobs/?position=Java+Developer
  </code></pre>
  
  <p>will be redirected to</p>
  
  <pre><code>domain.com/jobs/?position=Java+Developer
  </code></pre>
  
  <p>The first example successfully redirects the directory and the query string to all lowercase.</p>
  
  <p>The second example does not redirect the query string to lowercase, it remains the same.</p>
  
  <p>I can't figure out what to change in the code to get the query string to redirect to lowercase no matter if the directory or file name is uppercase or not.</p>
  
  <p>Here is the code:</p>
  
  <p><strong>htaccess</strong></p>
  
  <pre><code>RewriteEngine On
  
  RewriteBase /
  
  # force url to lowercase if upper case is found
  RewriteCond %{REQUEST_URI} [A-Z]
  RewriteRule (.*) rewrite-strtolower.php?rewrite-strtolower-url=$1 [QSA,L]
  </code></pre>
  
  <p><strong>PHP script</strong></p>
  
  <pre><code>&lt;?php
  if(isset($_GET['rewrite-strtolower-url'])) {
      $url = $_GET['rewrite-strtolower-url'];
      unset($_GET['rewrite-strtolower-url']);
      $params = http_build_query($_GET);
      if(strlen($params)) {
          $params = '?' . strtolower($params);
      }
      header('Location: http://' . $_SERVER['HTTP_HOST'] . '/' . strtolower($url) . $params, true, 301);
      exit;
  }
  header("HTTP/1.0 404 Not Found");
  die('Unable to convert the URL to lowercase. You must supply a URL to work upon.');
  ?&gt;
  </code></pre>