Google has discovered a pager in the sidebar of a website that allows the user to scroll through 'tags' while on a blog entry, each pager click taking you to a new url, e.g. example.com/blog/article-title?page=1
.
Since the blog has ~ 500 posts and the pager has ~ 140 pages of tags, Google has indexed a very high number of pages for my site. I don't want this for a number of reasons. I've already removed the pager on this tag block as it's completely unnecessary, but now would like to do 301 redirects on all of these ?page=X
URLs in the hopes that, over time, Google will remove them from their index.
The URLs look like this:
- http://example.com/blog/blog-article-title?page=0
- http://example.com/blog/blog-article-title?page=1
- http://example.com/blog/blog-article-title?page=2
How can I do a 301 redirect via htaccess that will send the user to http://example.com/blog/blog-article-title
?
I've tried many variations on
RewriteRule ^blog/(.*).?page(.*)$ /$1/blog/$2? [R=301,L]
and
RedirectMatch 301 ^/blog/(.*)\?page(.*)$ /blog/$1
but no luck thus far. Any help would be much appreciated.
Edit: For others that may stumble upon this, Google had completely ignored the canonical URL that is defined in the header and indexed all 30,000+ URL combinations. Doing the htaccess rewrite in the accepted answer below is properly performing a 301 on these pages. This, of course, requires that I move the pager elsewhere, but that's already been handled in my particular situation.