title: htaccess Redirect old URLs with query string to new SEO URLs
body: <p>I know this is a usual question/problem, but I've spent a few hours looking for an answer and I've found too many different solutions which differs too much from each other. I'd like to know which is the "best" way (best practice) to accomplish that.</p>
  
  <p>My htacces file looks like that:</p>
  
  <pre><code>RewriteEngine On
  
  # Redirect non-www URLs to www-prefixed ones
  RewriteCond %{HTTP_HOST} !^www\.
  RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
  
  # Redirect HTTPS requests to HTTP ones
  RewriteCond %{HTTPS} =on
  RewriteRule .* http://%{SERVER_NAME}%{REQUEST_URI} [R,L]
  
  # Redirect URLs with trailing slashes to ones without it
  RewriteRule ^([^/\.]+)/$ http://%{HTTP_HOST}/$1 [R=301,L]
  
  # Rewrite pretty URLs
  RewriteRule ^([^/\.]+)$ index.php?page=$1 [L]
  </code></pre>
  
  <p>Now the last important step is required: redirect the old URLs like</p>
  
  <p><code>http://www.domain.com/index.php?page=abc</code> and <code>http://www.domain.com/?page=abc</code></p>
  
  <p>to the new ones:</p>
  
  <p><code>http://www.domain.com/abc</code></p>
  
  <p>I know I should probably check <code>{QUERY_STRING}</code> and put this redirect BEFORE the last line which rewrites the URLs, or maybe not? How to correctly write such a rule?</p>