Forum Moderators: phranque

Message Too Old, No Replies

.htaccess redirect base on count

         

JamesTrix

12:23 pm on Aug 10, 2008 (gmt 0)

10+ Year Member



Is it possible to do a redirect based on some sort of count eg after 500 hits to redirect to another page/url

IF HIT COUNT > THAN 50 REDIRECT TO URL.COM

I know this could be a easy job if it was in PHP but wanted to see if it can be done in the htaccess

jdMorgan

1:27 pm on Aug 10, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No, it's the "count" part that makes this impossible in .htaccess.

The reason is that a server, by itself, has no "memory" of previous HTTP requests. It handles a request, and then promptly forgets about it; There are no persistent variables from one HTTP request to the next.

So, some mechanism must be added that 'remembers' things about previous requests. This usually takes the form of a PHP or PERL script which stores 'history' based on IP addresses, user-agents, URLs requested, etc. in a database, a flat file, or even one file per hashed IP address.

An example is the bad-bot script [webmasterworld.com] by xlcus and AlexK in our PHP forum.

Jim