Forum Moderators: phranque

Message Too Old, No Replies

Redirect on odd/even IP address

Change the page depending on user's IP address

         

zdigriz

10:38 pm on Aug 16, 2007 (gmt 0)

10+ Year Member



I want to test two different variations of a landing page as part of a marketing campaign (aka a/b test). It's important that once someone sees a particular page that they only see that page when the site is visited again.

If even IP addresses can be redirected to one page and odd IP addresses redirected to the other, it solves things pretty nicely without using any tracking information. Unless someone uses a different computer, they'll always see the same page as the first time.

Can mod_rewrite accomplish this? What would the statements be?

Thanks in advance!

jdMorgan

2:21 am on Aug 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



ISPs like AOL proxy their users' requests, and every user ends up using many values of the final IP address octet -- even for sequential HTTP requests while loading a single page and its included elements.

So, I'd recommend that you base the selection on the third, not the fourth, octet of the IP address.

See Apache mod_rewrite:


# Extract final digit of third Remote_Addr octet
RewriteCond %{REMOTE_ADDR} ^([0-9]+\.){2}[0-9]*([0-9])\.[0-9]+$
# IF final digit is odd
RewriteCond %2 ^[13579]$
# Then rewrite page.html to page-B.html
RewriteRule ^page\.html$ /page-B.html [L]
# ELSE rewrite page.html to page-A.html
RewriteRule ^page\.html$ /page-A.html [L]

"%2" is a back-reference to the value matched by the second parenthesized sub-pattern in the preceding RewriteCond, which is the last digit of the remote user's third IP address octet.

Jim