httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mraible <m...@raibledesigns.com>
Subject Re: [users@httpd] Is it possible for Apache to randomly select different URLs to serve up?
Date Fri, 20 Apr 2007 00:16:26 GMT

It seems there's two ways to do this and I can't get either one to work. 

#1: Using a perl script:

RewriteMap router prg:/opt/local/apache2/conf/router.pl
RewriteRule ^(.*)$ ${router} [R,L]

router.pl:

#!/usr/bin/perl
my $range = 3;
my $random_number = int(rand($range));

print "/?v=" . $random_number;

Going to "http://localhost" in my browser results in:

http://localhost/$%7brouter%7d

#2 Using rnd

RewriteMap servers rnd:/opt/local/apache2/conf/servers.map
RewriteRule ^(.*)$ ${servers} [R,L]

servers.map:
/?v=0|/?v=1|/?v=2

Going to "http://localhost" in my browser results in:

http://localhost/$%7bservers%7d

All my mod_rewrite settings follow the 2nd </Directory> in my httpd.conf.
This is the one that starts with:

<Directory "/opt/local/apache2/htdocs">

I'm using Apache 2.2.4 on OS X.

I have the following just before the RewriteMap lines:

RewriteEngine On
RewriteLog "/opt/local/apache2/logs/rewrite.log"

For some reason rewrite.log is created, but nothing is in it.

Thanks in advance for any help,

Matt
 

Joshua Slive-2 wrote:
> 
> On 4/18/07, Serge Dubrouski <sergeyfd@gmail.com> wrote:
>> A simple JavaScript serving as a main page and redirecting users to a
>> random URI from your site would do. I don't think that it would be
>> possible to do on Apache configuration level
>>
>> On 4/18/07, mraible <matt@raibledesigns.com> wrote:
>> >
>> > Is it possible for Apache to randomly select different URLs to serve
>> up?  For
>> > example:
>> >
>> > User1 -> http://my.domain.com/1
>> > User2 -> http://my.domain.com/2
>> > User3 -> http://my.domain.com/3
> 
> Actually, mod_rewrite can do it using a rnd: RewriteMap.
> 
> Joshua.
> 
> ---------------------------------------------------------------------
> The official User-To-User support forum of the Apache HTTP Server Project.
> See <URL:http://httpd.apache.org/userslist.html> for more info.
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>    "   from the digest: users-digest-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Is-it-possible-for-Apache-to-randomly-select-different-URLs-to-serve-up--tf3603013.html#a10089394
Sent from the Apache HTTP Server - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Mime
View raw message