title: Subfolder query string htaccess redirect
body: <p>Everything I can find for query string redirects talks about something like this:</p>
  
  <pre><code>RewriteEngine on 
  RewriteCond %{QUERY_STRING} ^view=home$
  RewriteRule .? http://mywebsite.com/? [L,R=301]
  </code></pre>
  
  <p>That's great, but I'm dealing with a url that looks like this:</p>
  
  <pre><code>example.com/portfolio/?gal=16
  </code></pre>
  
  <p>If I test it without the "portfolio/" it will work fine, but my old site is indexed as above. Any tips on how I can make it work with my URL structure?</p>
  
  <p><strong>EDIT</strong> Current .htaccess contents</p>
  
  <pre><code># BEGIN WordPress
  &lt;IfModule mod_rewrite.c&gt;
  RewriteEngine On
  RewriteBase /
  RewriteRule ^index\.php$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /index.php [L]
  &lt;/IfModule&gt;
  
  # END WordPress
  
  # Canonical Remove www
  RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
  RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
  
  # Redirects
  
  Redirect 301 /feedback http://example.com/testimonials
  Redirect 301 /about http://example.com/about-us
  Redirect 301 /contact http://example.com/contact-us
  
  #futile attempts at query string redirects omitted
  </code></pre>
  
  <p>Thanks.</p>
  
  <p><strong>New Edit to include @anubhava's suggestions</strong></p>
  
  <p>Might as well give you the actual .htaccess content since the site is now live.</p>
  
  <pre><code># BEGIN WordPress
  &lt;IfModule mod_rewrite.c&gt;
  RewriteEngine On
  RewriteBase /
  
  RewriteCond %{HTTP_HOST} ^dev.bayshorephotography.com$ [OR]
  RewriteRule (.*)$ http://bayshorephotography.com/$1 [R=301,L]
  
  # Canonical Remove www
  RewriteCond %{HTTP_HOST} ^www.bayshorephotography.com$ [NC]
  RewriteRule ^(.*)$ http://bayshorephotography.com/$1 [R=301,L]
  
  RewriteCond %{QUERY_STRING} ^gal=16$
  RewriteRule .? http://bayshorephotography.com/portfolio/weddings-02/? [L,R=301]
  
  Redirect 301 /feedback http://bayshorephotography.com/testimonials
  Redirect 301 /about http://bayshorephotography.com/about-us
  Redirect 301 /contact http://bayshorephotography.com/contact-us
  
  #301 Redirect Entire Directory to remove /blog/ from all blog pages except the main archive itself
  RedirectMatch 301 /blog(/.*)/ $1
  
  RewriteRule ^index\.php$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /index.php [L]
  &lt;/IfModule&gt;
  
  # END WordPress
  
  # Old Redirects that don't work
  #Redirect 301 /portfolio?gal=20 http://bayshorephotography.com/portfolio-items/weddings-04/
  #Redirect 301 /portfolio?gal=29 http://bayshorephotography.com/portfolio-items/our-world-03/
  #Redirect 301 /portfolio?gal=16 http://bayshorephotography.com/portfolio-items/weddings-02/
  #Redirect 301 /portfolio?gal=18 http://bayshorephotography.com/portfolio-items/weddings-04/
  #Redirect 301 /portfolio?gal=28 http://bayshorephotography.com/portfolio-items/album-samples-01/
  #Redirect 301 /portfolio?gal=19 http://bayshorephotography.com/portfolio-items/weddings-05/
  #Redirect 301 /portfolio?gal=22 http://bayshorephotography.com/portfolio-items/portraits-01/
  #Redirect 301 /portfolio?gal=24 http://bayshorephotography.com/portfolio-items/our-world-01/
  #Redirect 301 /portfolio?gal=17 http://bayshorephotography.com/portfolio-items/weddings-03/
  #Redirect 301 /portfolio?gal=36 http://bayshorephotography.com/portfolio-items/portraits-04/
  #Redirect 301 /portfolio?gal=35 http://bayshorephotography.com/portfolio-items/portraits-03/
  #Redirect 301 /portfolio?gal=32 http://bayshorephotography.com/portfolio-items/weddings-01/
  #Redirect 301 /portfolio?gal=25 http://bayshorephotography.com/portfolio-items/our-world-02/
  #Redirect 301 /portfolio?gal=23 http://bayshorephotography.com/portfolio-items/portraits-02/
  #Redirect gone /portfolio?gal=34
  #Redirect gone /portfolio?gal=33
  #Redirect gone /portfolio?gal=27
  #Redirect gone /portfolio?gal=21
  </code></pre>