Reputation: 4421
is it somehow possible to randomly redirect purely in htaccess? (without need of php) Something like:
rand_pool() = ['a.php', 'b.php', 'c.php']
RewriteRule ^page.php$ /rand_pool() [R=301,L]
Upvotes: 1
Views: 1869
Reputation: 6860
You can use RewriteMap directive for this.
First you need to generate a map file:
## random.map -- rewriting map
randomX a.php|b.php|c.php
You can generate as many values (separated by |
) as needed, however I don't know if there is any limit in apache regarding their count.
Then you define the Randomized Plain Text type of rewrite map using this file and finally use it in your rewrite rule.
RewriteMap randomMap rnd:/path/to/random.map
RewriteRule ^page\.php$ /${randomMap:randomX} [P,L]
Upvotes: 1
Reputation: 20737
No, this is not possible, at least not with any amount of efficiency. One might be able to abuse mod_unique_id to generate an unique id, then reduce this id to a new page, but this is at best dodgy.
Instead internally rewrite to a router page, then perform the necessary redirect on this page. When maintaining the code, it will be much more clear what you wanted to achieve with this.
Upvotes: 0