I seem to be having trouble applying any examples I’ve found for stripping query strings.
We have a WordPress installation at http://www.example.com/blog/ , and for some reason, even though our categories are set to pretty slugs (IE http://www.example.com/categories/cat-name/ ), and even though I can never find any of the links on the reported referrer pages, Google webmaster tools keeps trying and failing to index http://www.example.com/blog/?cat=3, ?cat=25, ?cat=37, etc. In fact, right now it’s showing a little over 50 such URLs up to category #81, however we only have 11 categories.
The correct category URLs are indexed, and I’d like to just strip all of those query strings, and redirect to http://www.example.com/blog/, but none of the examples seem to work… here’s my latest attempt (in the webspace root… attempts in /blog/.htaccess have been fruitless as well):
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com [OR]
RewriteCond %{REQUEST_URI} /index\.html$
RewriteRule (.*?)(index\.html)?$ http://www.example.com/$1 [NE,R=301,L]
RewriteCond %{REQUEST_URI} \.jpg.+$
RewriteRule ^(.*\.jpg).*$ http://www.example.com/$1 [NE,R=301,L]
RewriteCond %{QUERY_STRING} ^cat=([0-9]*)$
RewriteRule ^(.*)$ http://www.example.com/blog/ [R=301,L]
Thanks in advance. Note the first group of rules enforces “www.”, and no “index.html”, and the second group drops everything after “.jpg”, as we had an odd issue with Google trying to index urls that ended in wierd ways, like “.jpg%20>”, as if it somehow missed the closing quotes of an anchor’s source, but I never could find such errors in the site… referrer was always a 300 error page.
If you want to completely strip off a query string, end your replacement string with a
?.From the Apache Rewrite docs: