homepage Welcome to WebmasterWorld Guest from 54.145.209.80
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
mod_rewrite to more than 1 page
mod_rewrite to more than 1 page
planbeta

10+ Year Member



 
Msg#: 239 posted 11:38 am on Jun 13, 2003 (gmt 0)

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

 

DaveAtIFG

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 239 posted 2:23 pm on Jun 14, 2003 (gmt 0)

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.

Slade

10+ Year Member



 
Msg#: 239 posted 3:02 pm on Jun 14, 2003 (gmt 0)

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.

jdMorgan

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



 
Msg#: 239 posted 3:12 pm on Jun 14, 2003 (gmt 0)

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

Storyteller

10+ Year Member



 
Msg#: 239 posted 9:09 pm on Jun 14, 2003 (gmt 0)

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.
jdMorgan

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



 
Msg#: 239 posted 9:54 pm on Jun 14, 2003 (gmt 0)

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

planbeta

10+ Year Member



 
Msg#: 239 posted 7:31 am on Jun 15, 2003 (gmt 0)

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

Cheers

Chris

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.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved