phpBB SEO
Boards
Directory  
SEO  
Downloads
  phpBB SEO : Search Engine Optimization, Directory, Forums  
Index
Forums
Annuaire
Référencement
Télécharger
 
  Search Rechercher
    Register
Username :  Password :  Log me on automatically each visit  
S'enregistrer  
 
   
Help me redirect by IP

 
Post new topic   Reply to topic    phpBB SEO » SEO Forum  » Apache mod Rewrite
::  
Author Message
huyhoa



Joined: 02 Dec 2006
Posts: 9

Help me redirect by IPPosted: Sat Dec 02, 2006 1:26 pm    Post subject: Help me redirect by IP

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:

Quote:
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{HTTP_HOST} !^www\.abc\.com\abc.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/abc.htm$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/index.htm$1 [R=301,L]


But now i want more ip range, like this:

Quote:
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
Back to top
dcz
Administrateur - Site Admin
Administrateur - Site Admin


Joined: 28 Apr 2006
Posts: 14403

Help me redirect by IPPosted: Sat Dec 02, 2006 3:03 pm    Post subject: Re: Help me redirect by IP

And welcome Very Happy

Interesting example actually.

So you have two custom versions of you web site, and one English speaking one and you want to filter IP for the first two.

There must be some Geo-location services to do the same using php, but if you're pretty sure about your IP list, then, it can be faster to do it at the server level.

The only thing is we don't want a 10 000 lines long .htaccess. A RewriteMap could help out to deal with larger amount of URLs.

So far it's still ok to add one RewriteCond per ip range. You'd just need some optimization.

If we look at the first few ip ranges posted :
Quote:

210.245.0.0 - 210.245.31.255

210.245.32.0 - 210.245.63.255

210.245.64.0 - 210.245.127.255


it looks like it's possible to only deal with :
210.245.0.0 - 210.245.127.255

Which can be taken car of with :

Code:
RewriteCond %{REMOTE_ADDR} ^210\.245\.(0?[0-9]|1[0-1][0-9]|12[0-7])\.([0-9]){1,3}$ [OR]


So you first need to group your ip ranges in order to use a few RewriteCond as possible and just proceed as you started too.

A CGI script could be used together with a rewrite map in order to match IPs outside the .htaccess, but this is another story to set up.

++

_________________
Useful links :
SEO Forum || SEO Directory || SEO phpBB || SEO phpBB3 || Search
____________________

Liens Utiles :
Forum référencement || Annuaire référencement || Référencement phpBB || Référencement phpBB3 || Recherche
Back to top
Visit poster's website
huyhoa



Joined: 02 Dec 2006
Posts: 9

Help me redirect by IPPosted: Thu Jan 11, 2007 5:18 pm    Post subject: Re: Help me redirect by IP

Hic hic, this is the list
203.210.128.0 - 203.210.159.255
210.245.0.0 - 210.245.127.255
58.186.0.0 - 58.187.255.255
125.134.0.0 - 125.135.255.255
203.162.88.0 - 203.162.255.255
222.252.0.0 - 222.252.255.255
203.113.128.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.54.255
221.132.0.0 - 221.132.63.255

And follow you, i creat:
Code:
RewriteCond %{REMOTE_ADDR} ^210\.245\.(0?[0-9]|1[0-1][0-9]|12[0-7])\.([0-9]){1,3}$ [OR]
RewriteCond %{REMOTE_ADDR} ^221\.132\.(0?[0-9]|1[0-1][0-9]|6[0-3])\.([0-9]){1,3}$ [OR]

(this for 221.132.0.0 - 221.132.63.255)
Code:
RewriteCond %{REMOTE_ADDR} ^203\.162\.(0?[0-9]|1[0-1][0-9]|5[0-4])\.([0-9]){1,3}$ [OR]

this for 203.162.0.0 - 203.162.54.255
Code:
RewriteCond %{REMOTE_ADDR} ^222\.252\.(0?[0-9]|1[0-1][0-9]|25[0-5])\.([0-9]){1,3}$ [OR]

(This for 222.252.0.0 - 222.252.255.255)

Is this right?
and this, i dont know how to do?
203.210.128.0 - 203.210.159.255
203.162.88.0 - 203.162.255.255
203.113.128.0 - 203.113.191.255
220.231.64.0 - 220.231.127.255
203.41.55.0 - 203.41.55.255
Please tell me is this right and help me rewrite this:
203.210.128.0 - 203.210.159.255
203.162.88.0 - 203.162.255.255
203.113.128.0 - 203.113.191.255
220.231.64.0 - 220.231.127.255
203.41.55.0 - 203.41.55.255
Back to top
huyhoa



Joined: 02 Dec 2006
Posts: 9

Help me redirect by IPPosted: Thu Jan 11, 2007 7:37 pm    Post subject: and help me,

Quote:
RewriteCond %{HTTP_HOST} !^www\.dmtcenter\.com$ [NC]

RewriteCond %{REMOTE_ADDR} ^210\.245\.(0?[0-9]|1[0-1][0-9]|12[0-7])\.([0-9]){1,3}$ [OR]
RewriteCond %{REMOTE_ADDR} ^203\.162\.(0?[0-9]|1[0-1][0-9]|5[0-4])\.([0-9]){1,3}$ [OR]
RewriteCond %{REMOTE_ADDR} ^222\.252\.(0?[0-9]|1[0-1][0-9]|25[0-5])\.([0-9]){1,3}$ [OR]
RewriteCond %{REMOTE_ADDR} ^221\.132\.(0?[0-9]|1[0-1][0-9]|6[0-3])\.([0-9]){1,3}$ [OR]
RewriteRule ^(.*)$ http://www.dmtcenter.com/$1 [R=301,L]

RewriteCond %{HTTP_HOST} !^www\.huyhoa\.biz$ [NC]
RewriteCond %{REMOTE_ADDR} !^210\.245\.(0?[0-9]|1[0-1][0-9]|12[0-7])\.([0-9]){1,3}$ [OR]
RewriteCond %{REMOTE_ADDR} !^203\.162\.(0?[0-9]|1[0-1][0-9]|5[0-4])\.([0-9]){1,3}$ [OR]
RewriteCond %{REMOTE_ADDR} !^222\.252\.(0?[0-9]|1[0-1][0-9]|25[0-5])\.([0-9]){1,3}$ [OR]
RewriteCond %{REMOTE_ADDR} !^221\.132\.(0?[0-9]|1[0-1][0-9]|6[0-3])\.([0-9]){1,3}$ [OR]
RewriteRule ^(.*)$ http://www.huyhoa.biz/diendan/$1 [R=301,L]

Iuse it, but when i type : http://huyhoa.biz --> http://www.dmtcenter.com if Ip vietnam , other i dont test. please test it for me, and if i type http://www.huyhoa.biz/diendan --> it ok even ip is vietnam. how can i fix it.
Back to top
dcz
Administrateur - Site Admin
Administrateur - Site Admin


Joined: 28 Apr 2006
Posts: 14403

Help me redirect by IPPosted: Thu Jan 11, 2007 11:05 pm    Post subject: Re: Help me redirect by IP

Actually, since we're testing ips as text strings this way, we can do the following for ip ranges :

Something like :
221.132.0.0 - 221.132.63.255
Code:

RewriteCond %{REMOTE_ADDR} ^221\.132\.[0-6]{2}\. [OR]

203.162.0.0 - 203.162.54.255
Code:
RewriteCond %{REMOTE_ADDR} ^203\.162\.[0-5]{2}\. [OR]


Could work faster.

++

_________________
Useful links :
SEO Forum || SEO Directory || SEO phpBB || SEO phpBB3 || Search
____________________

Liens Utiles :
Forum référencement || Annuaire référencement || Référencement phpBB || Référencement phpBB3 || Recherche
Back to top
Visit poster's website
huyhoa



Joined: 02 Dec 2006
Posts: 9

Help me redirect by IPPosted: Fri Jan 12, 2007 6:52 am    Post subject: thanks

Quote:
#Ngan cam IP Vietnam

RewriteCond %{HTTP_HOST} !^www\.dmtcenter\.com$ [NC]
RewriteCond %{REMOTE_ADDR} ^221\.132\.[0-6]{2}\. [OR]
RewriteCond %{REMOTE_ADDR} ^203\.162\.[0-5]{2}\. [OR]
RewriteCond %{REMOTE_ADDR} ^222\.252\.[0-5]{2}\. [OR]
RewriteRule ^(.*)$ http://www.dmtcenter.com/$1 [R=301,L]

RewriteCond %{HTTP_HOST} !^www\.huyhoa\.biz$ [NC]
RewriteCond %{REMOTE_ADDR} !^221\.132\.[0-6]{2}\. [OR]
RewriteCond %{REMOTE_ADDR} !^203\.162\.[0-5]{2}\. [OR]
RewriteCond %{REMOTE_ADDR} !^222\.252\.[0-5]{2}\. [OR]
RewriteRule ^(.*)$ http://www.huyhoa.biz/$1 [R=301,L]
## KEt thuc ngan cam

I use this code to direct visitor, when type dmtcenter.com or huyhoa.biz, i mean if people from ip 222.132.0.0 - 221.132.64.255, 203.162.0.0 - 203.162.54.255 and 222.252.0.0 - 222.252.255.255 will direct to dmtcenter.com and if other, will direct to http://huyhoa.biz/diendan/ dont care about they type huyhoa.biz or dmtcenter.com or news.dmtcenter.com and dont allow to type direct huyhoa.biz/diendan to enter or dmtcenter.com/news to enter.
but it alway direct to dmtcenter.com and dont go to huyhoa.biz even my ip is 70.176.47.246 ( i use sock proxy )
any mistake here?
Back to top
dcz
Administrateur - Site Admin
Administrateur - Site Admin


Joined: 28 Apr 2006
Posts: 14403

Help me redirect by IPPosted: Fri Jan 12, 2007 11:17 am    Post subject: Re: Help me redirect by IP

Was thinking that the {2} should rather be {1,2} eg on or two chars, which works nice when we want 2 digit, like for .54. or {1,3} is you'd up to three digit.

This way you'll redirect few IP that should not, but it's fast and light.

About the ending .com, when I load dmtcenter.com/, I feel on news.dmtcenter.com right now.

So I think :

Code:
RewriteCond %{HTTP_HOST} !^www\.dmtcenter\.com$ [NC]


Should be :


Code:
RewriteCond %{HTTP_HOST} ^(.+)\.dmtcenter\.com$ [NC]

To deal at once with all sub domains, for the .com.

And :

Code:
RewriteRule ^(.*)$ http://www.dmtcenter.com/$1 [R=301,L]


should be :

Code:
RewriteRule ^(.*)$ http://%1.dmtcenter.com/$1 [R=301,L]


Where %1 stands for the captured sub domain.

And this means, you must take care of the possible www and sub domains duplicate at first, which with the multi domain setting of yours is a bit more tricky than usual.

First you should make sure that :

Code:
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*) http://www.example.com/$1 [QSA,L,R=301]


For both domains, eg, if the www, was not entered, and no sub domain either, force the www prefix And let subdomains work the same.

This way, you'll always have something.example.com, and the above filter should work in all cases : www, news, etc ...

++

_________________
Useful links :
SEO Forum || SEO Directory || SEO phpBB || SEO phpBB3 || Search
____________________

Liens Utiles :
Forum référencement || Annuaire référencement || Référencement phpBB || Référencement phpBB3 || Recherche
Back to top
Visit poster's website
huyhoa



Joined: 02 Dec 2006
Posts: 9

Help me redirect by IPPosted: Sat Jan 13, 2007 4:03 am    Post subject: Re: Help me redirect by IP

Follow your help, i had been changes code to this:
Quote:
#Ngan cam IP Vietnam

RewriteCond %{HTTP_HOST} ^(.+)\.dmtcenter\.com$ [NC]
RewriteCond %{REMOTE_ADDR} ^221\.132\.[0-6]{1,2}\. [OR]
RewriteCond %{REMOTE_ADDR} ^203\.162\.[0-5]{1,2}\. [OR]
RewriteCond %{REMOTE_ADDR} ^222\.252\.[0-5]{1,3}\. [OR]
RewriteRule ^(.*)$ http://%1.dmtcenter.com/$1 [R=301,L]

RewriteCond %{HTTP_HOST} !^www\.huyhoa\.biz$ [NC]
RewriteCond %{REMOTE_ADDR} !^221\.132\.[0-6]{1,2}\. [OR]
RewriteCond %{REMOTE_ADDR} !^203\.162\.[0-5]{1,2}\. [OR]
RewriteCond %{REMOTE_ADDR} !^222\.252\.[0-5]{1,3}\. [OR]
RewriteRule ^(.*)$ http://www.huyhoa.biz/$1 [R=301,L]
## KEt thuc ngan cam


I mean:
Quote:
RewriteCond %{REMOTE_ADDR} ^221\.132\.[0-6]{1,2}\. [OR]

Quote:
For 221.132.0.0 - 221.132.63.255

Quote:
RewriteCond %{REMOTE_ADDR} ^203\.162\.[0-5]{1,2}\. [OR]

Quote:
for: 203.162.0.0 - 203.162.54.255

And:
Quote:
RewriteCond %{REMOTE_ADDR} ^222\.252\.[0-5]{1,3}\. [OR]

Quote:
For: 222.252.0.0 - 222.252.255.255

But still dont work.
So, please give me some minute to help me, code this:
The list Ip is :
Quote:
203.210.128.0 - 203.210.159.255
210.245.0.0 - 210.245.127.255
58.186.0.0 - 58.187.255.255
125.134.0.0 - 125.135.255.255
203.162.88.0 - 203.162.255.255
222.252.0.0 - 222.252.255.255
203.113.128.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.54.255
221.132.0.0 - 221.132.63.255


Please code how to enter -http://huyhoa.biz -http://dmtcenter.com -http://www.huyhoa.biz/diendan/ and -http://dmtcenter.com/news , it will alway chack ip first, if ip in range of the list above, will redirect to -http://news.dmtcenter.com
and if dont in range of the list above, will move to -http://huyhoa.biz/diendan

Thanks for your help.
Back to top
dcz
Administrateur - Site Admin
Administrateur - Site Admin


Joined: 28 Apr 2006
Posts: 14403

Help me redirect by IPPosted: Sat Jan 13, 2007 8:57 am    Post subject: Re: Help me redirect by IP

What about :
Code:
RewriteCond %{REMOTE_ADDR} ^221\.132\.[0-6]{1} [OR]



Quote:
For 221.132.0.0 - 221.132.63.255



Code:
RewriteCond %{REMOTE_ADDR} ^203\.162\.[0-5]{1} [OR]


Quote:

for: 203.162.0.0 - 203.162.54.255


And:
Code:

RewriteCond %{REMOTE_ADDR} ^222\.252\.[0-2]{1} [OR]


Quote:

For: 222.252.0.0 - 222.252.255.255


it will be a bit less strict, as we only test the first digit of the last range, but should work.
++

_________________
Useful links :
SEO Forum || SEO Directory || SEO phpBB || SEO phpBB3 || Search
____________________

Liens Utiles :
Forum référencement || Annuaire référencement || Référencement phpBB || Référencement phpBB3 || Recherche
Back to top
Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    phpBB SEO » SEO Forum  » Apache mod Rewrite
Page 1 of 1

Navigation Similar Topics

Jump to: