Welcome to WebmasterWorld Guest from 174.129.96.175

Forum Moderators: Ocean10000 & incrediBILL & phranque

mod_rewrite to more than 1 page

mod_rewrite to more than 1 page

   
11:38 am on Jun 13, 2003 (gmt 0)

10+ Year Member



Hello

I know how to set up mod_rewrite to rewrite to a different page than the one accessed eg. RewriteRule mypage\.htm otherpage.htm

I don't know if this is possible, but instead of rewriting to a specific page can you rewrite to more than one page, either randomly selecting or possibley selecting an equal amount of times each page from a predefined list of pages?

Any help/pointers would be great.

Cheers

Chris

2:23 pm on Jun 14, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hey plan b, I'll give you a definite maybe to this question! :)

According to Apache, the format for a RewriteRule is:

RewriteRule Pattern Substitution

so you cannot rewrite to a random "Substitution" target.

As you know, RewriteCond directives permit us to "massage" RewriteRules, making them conditional. I think you could create a condition (based on time of day perhaps) that would send visitors to different pages and it would appear to be a page selected at random.

3:02 pm on Jun 14, 2003 (gmt 0)

10+ Year Member



You might find it easier to rewrite to a script instead.

Then have the script 302 (I think this would be best here) to a random other page.

3:12 pm on Jun 14, 2003 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



planbeta,

The following rules will rewrite to file1.html if the current time is 0 to 29 seconds into the current minute, and to file2.html otherwise. If the first pattern matches, then we rewrite to file1 and stop rewriterule processing because of the [L] flag. Otherwise, the code falls through to the second rule, and we rewrite to file2.html and stop rewriterule processing.


RewriteCond %{TIME_SEC} ^[0-2][0-9]$
RewriteRule ^file\.html$ /file1.html [L]
RewriteRule ^file\.html$ /file2.html [L]

Ref: Apache mod_rewrite RewriteCond [httpd.apache.org]

HTH,
Jim

9:09 pm on Jun 14, 2003 (gmt 0)

10+ Year Member



planbeta, use
RewriteMap
option. It lets you do random-based rewrites easily or hook up an external script, if that's not enought. This is pretty well covered in the standard Apache documentation, as far as I recall.
9:54 pm on Jun 14, 2003 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



planbeta,

RewriteMap with randomized plain-text option would give you the random effect you asked for. However, RewriteMap is not available in a per-directory (.htaccess) context. :(

Jim

7:31 am on Jun 15, 2003 (gmt 0)

10+ Year Member



Thanks for all your suggestions folks. I'm testing them out now! :)

Cheers

Chris

 

Featured Threads

My Threads

Hot Threads This Week

Hot Threads This Month