开发者

RewriteEngine question in .htaccess

开发者 https://www.devze.com 2023-03-25 09:20 出处:网络
I have 开发者_如何转开发put this in my htaccess #Redirect all england visitor to this web page , england.php

I have 开发者_如何转开发put this in my htaccess

#Redirect all england visitor to this web page , england.php
RewriteEngine On
RewriteCond %{REMOTE_ADDR} ^222\.167\. [OR]
RewriteCond %{REMOTE_ADDR} ^112\.111\. 
........
RewriteRule ^(.*)$ http://www.xxx.com/england.php  [R=302,L] 

While non-england visitors will land in index.php

However, i have found that, england visitors can visit this website www.xxx.com/england.php if there type the address in address bar. How can make this page only available to england ip address? thx


A better approach would be to use mod_authz_host and "deny for all" by default, then only allow the IP ranges you want to let in. Finally, add an ErrorPage that redirects forbidden visitors to the index page.

See the Apache manual.


Obviously you need to know which IP addresses are in England.

You can get the data you require from something like http://www.maxmind.com/app/geolitecountry. You can then look up the IP address and determine it's location.

I don't know if putting the data in the .htaccess will be a viable solution.

Quote from the maxmind site...

Due to the large size of geolocation databases, we generally recommend using our binary format with one of our APIs, since they are highly optimized for speed and disk space. On the other hand, if you have a requirement to import the data into a SQL database, the CSV format is recommended. We have listed some guidelines for importing and querying the data with a SQL database.

But I guess you can try it and see..

0

精彩评论

暂无评论...
验证码 换一张
取 消