URL rewrite for pagination

A lot of sites I see using pagination all hit a similar problem.  The URL of the initial page looks lovely with no URL parameters or alike just news.aspx or news.php.

As you navigation through the additional pages the ?page=2, etc. gets added – again not too bad but the annoying bit comes when you click on the “page 1” link again and instead of going back to that nice URL you just had, it simple appends ?page=1 to the end.

Now this works fine for us, visitors, etc. but the problem is this is really bad SEO – as two pages have the same content but spiders see this as two different pages.

So how about a fix?  Well it’s actually easy enough to do this through a rewrite rule – no additional coding or tweaking to the pagination code you have in place!  So here it is:

# Don't display pager for first page
  RewriteCond %{QUERY_STRING} page=1
  RewriteRule (.*) /$1? [L,R=301]