Help me, redirect by IP

New to mod_rewrite? This is a good place to start.

Help me, redirect by IP

Postby huyhoa » Tue Nov 28, 2006 2:45 am

I want make a web like google, when visitor comfrom ip range
203.123.0.0 to 203.123.31.26 and 67.27.0.22 to 67.27.27.89 , homepage will automatically direct to abc.com.vn/abc.htm ( i mean abc.com.vn/abc.htm is my domain language by vietnamese) and other ip will automatically direct to abc.com.vn (abc.com.vn is my english website).


I use this code:
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{HTTP_HOST} !^www\.abc\.com\.vn\.htm$    [NC]
RewriteCond %{REMOTE_ADDR} ^203\.123\.((0*[0-9]|0*[12][0-9]+|0?30)\.[0-9]+|0?31\.(0*[0-9]|0?1[0-9]+|0?2[1-6]))$ [OR]
RewriteCond %{REMOTE_ADDR} ^0?67\.0?27\.(0+\.[0-9]+|(0*1?[0-9]|2[0-6])\.[0-9]+|27\.(0+|0?[1-8][0-9]))$
RewriteRule ^(.*)$ http://www.abc.com.vn/$1 [R=301,L]

RewriteCond %{HTTP_HOST} !^www\.abc\.com$        [NC]
RewriteCond %{REMOTE_ADDR} !^203\.123\.((0*[0-9]|0*[12][0-9]+|0?30)\.[0-9]+|0?31\.(0*[0-9]|0?1[0-9]+|0?2[1-6]))$
RewriteCond %{REMOTE_ADDR} !^0?67\.0?27\.(0+\.[0-9]+|(0*1?[0-9]|2[0-6])\.[0-9]+|27\.(0+|0?[1-8][0-9]))$
RewriteRule ^(.*)$ http://www.abc.com/$1    [R=301,L]


But now i want more ip range, like this:
Code: Select all
210.245.0.0 - 210.245.31.255
210.245.32.0 - 210.245.63.255
210.245.64.0 - 210.245.127.255
58.186.0.0 - 58.186.255.255
58.187.0.0 - 58.187.255.255
125.234.0.0 - 125.234.255.255
125.235.0.0 - 125.235.255.255
203.113.128.0 - 203.113.159.255
203.113.160.0 - 203.113.191.255
220.231.64.0 - 220.231.127.255
203.41.55.0 - 203.41.55.255
203.160.0.0 - 203.160.1.255
203.162.0.0 - 203.162.7.255
203.162.8.0 - 203.162.15.255
203.162.16.0 - 203.162.31.255
203.162.32.0 - 203.162.47.255
203.162.48.0 - 203.162.51.255
203.162.52.0 - 203.162.53.255
203.162.54.0 - 203.162.54.255
203.162.88.0 - 203.162.95.255
203.162.96.0 - 203.162.127.255
203.162.128.0 - 203.162.143.255
203.162.144.0 - 203.162.175.255
203.162.176.0 - 203.162.191.255
203.162.192.0 - 203.162.255.255
203.210.128.0 - 203.210.143.255
203.210.144.0 - 203.210.159.255
203.210.192.0 - 203.210.255.255
221.132.0.0 - 221.132.63.255
222.252.0.0 - 222.252.255.255
222.253.0.0 - 222.253.255.255
222.254.0.0 - 222.254.255.255
222.255.0.0 - 222.255.255.255


I think it hard to do, so can anyone can did it in php?
I mean in index.php make a redirect, when visitor from the above ip then redirect to abc.com.vn/abc.htm
And other, will redirect to abc.com.vn/home.php
huyhoa
 
Posts: 35
Joined: Tue Nov 28, 2006 2:25 am

Return to Beginner's Corner

Who is online

Users browsing this forum: Google [Bot] and 38 guests

cron