Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Redirect page range



10:02 pm on Mar 22, 2011 (gmt 0)

10+ Year Member

Hi, I've searched the forums for an example I could base what I need on, but haven't had much luck in what I've tried,

What I need to do is to redirect a range of pages to a single page. For example, any page with an ID of 21 (e.g http://www.example.com/blogs?Page=21)or higher needs to be 301 redirected to a single page.

Here's what I've tried:

RedirectMatch 301 ^/blogs?Page=[21-100000]$ http://www.example.com/file.htm

.. could someone please tell me where I've gone wrong?

Thanks in advance for your assistance


10:18 pm on Mar 22, 2011 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

Many places, but two major things stop it dead.

RedirectMatch cannot "see" query string parameter data and [21-100000] matches any single digit 0, 1 or 2 or a hyphen.

I would do this:

# For page=0-9,00-09,10-19: do nothing.
RewriteCond %{QUERY_STRING} &?Page=[01]?[0-9](&.*)?$
RewriteRule ^blogs - [L]

# For other pages: redirect.
RewriteCond %{QUERY_STRING} &?Page=[0-9]+
RewriteRule ^blogs http://www.example.com/page.html [R=301,L]


8:44 am on Mar 23, 2011 (gmt 0)

10+ Year Member

Thanks g1smd - I tried it out and it redirected all Page= pages for some reason, but what you provided put me on track to create something that will address the issue:

RewriteCond %{QUERY_STRING} &?Page=(2[1-9]|[3-9][0-9]|[1-9][0-9]{2,4}|100000)
RewriteRule ^blogs http://www.example.com/file-not-found.html [R=301,L]

Handles all page= IDs from 21 - 100,000. I'm sure there's better/more elegant ways to address this (like fixing the software that's generating the empty pages that Google is indexing for some reason), but it will get me out of trouble for the moment.

Thanks again for your help, it was *greatly* appreciated .. and I got to learn a little about number ranges along the way, very useful.


8:59 am on Mar 23, 2011 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

I can't see the logic error in my first rule that stops it matching. It should have matched anything in the range 0 to 19 and then quit. I was trying to avoid a complex (and therefore slow) pattern for the matching.

You should not redirect to a "file not found" page. For pages that don't exist, you were returning "200 OK", and now you return "301" followed by "200 OK". This gives your site infinite URL space and searchengines don't like that.

Return "404 Not Found" or "410 Gone", perhaps using:
RewriteRule ^blogs - [G]

Be aware that 2[1-9] matches 21 to 29 but it also matches 21038383838383388 and 2937272288882 - which in this case isn't a problem.

A simpler pattern might be:

This matches 21-29 or 100-299 and 1000-2999 and 10000-29999 or 30-99 and 300-999 and 3000-9999 and 30000-99999 and so on.

[edited by: g1smd at 9:39 am (utc) on Mar 23, 2011]


9:19 am on Mar 23, 2011 (gmt 0)

10+ Year Member

Re: your first rule - possibly I implemented it incorrectly, I'll give it another try.

I had the new destination page robots.txt'd out, but "410 Gone" is certainly a much better approach, implemented that, working fine; thanks again.

Re: those bigger numbers, yep, aware; but thanks for flagging it.

Featured Threads

Hot Threads This Week

Hot Threads This Month