homepage Welcome to WebmasterWorld Guest from 184.73.52.98
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Accredited PayPal World Seller

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Redirect page range
icarus




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

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

 

g1smd




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

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]

icarus




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

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.

g1smd




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

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:
Page=([2][1-9]|[12][0-9]{2,}|[3-9][0-9]{1,})($|&)
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]

icarus




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

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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved