.htaccess question please

B

BusyGuy

Folks, sorry to ask a newbie question.

Let's say I have two directories, each of which will contain an index
file. Site visitors are, at present, routed to one of these when they
click the relevant link on other pages.

I would like to place a .htaccess file and have it inspect the IP
address of the visitor. If that IP address falls within certain ranges
it will route the visitor to one of the above directories. If not, it
will direct to the other.

I would appreciate a hint to the correct code please.
 
J

Jukka K. Korpela

BusyGuy said:
Folks, sorry to ask a newbie question.

It's not a newbie question, really. You are trying to make things difficult
in an advanced way.
I would like to place a .htaccess file and have it inspect the IP
address of the visitor. If that IP address falls within certain ranges
it will route the visitor to one of the above directories.

What problem do you expect to solve with such an approach? The odds are
about 99 against 0 that you are trying to solve a wrong problem and end up
with _creating_ a problem.
 
B

BusyGuy

Jukka K. said:
It's not a newbie question, really. You are trying to make things difficult
in an advanced way.


What problem do you expect to solve with such an approach? The odds are
about 99 against 0 that you are trying to solve a wrong problem and end up
with _creating_ a problem.

I want to direct any visitors from one specific country to a specific
page. All others can go to an alternative page. I would certainly
welcome an easier way to do it.
 
J

Jukka K. Korpela

BusyGuy said:
I want to direct any visitors from one specific country to a specific
page.

That's what I suspected. So you _are_ solving the wrong problem.

You have no way of knowing what country I am from, for any definition for
being from a particular country. In particular, you cannot tell it from my
IP address, especially not when I am travelling abroad. Trying to guess the
country from an IP range is simply nonsensical.

Besides, people often actually mean language when they say "country".

So think again. _If_ you really have some special content for people who are
from Borduria (the proverbial country, you know), simply put a link to such
content on your main page. Such as "Special prices apply in Borduria",
making this expression a link. Problem solved.
 
B

BusyGuy

Jukka K. said:
That's what I suspected. So you _are_ solving the wrong problem.

You have no way of knowing what country I am from, for any definition for
being from a particular country. In particular, you cannot tell it from my
IP address, especially not when I am travelling abroad. Trying to guess the
country from an IP range is simply nonsensical.

Besides, people often actually mean language when they say "country".

So think again. _If_ you really have some special content for people who are
from Borduria (the proverbial country, you know), simply put a link to such
content on your main page. Such as "Special prices apply in Borduria",
making this expression a link. Problem solved.

Thanks very much, Jukka, I appreciate your reply.

Unfortunately, it doesn't help me and I truly hope you are a little bit
incorrect.

I did a search and found myself here
<http://software77.net/cgi-bin/ip-country/geo-ip.pl> but I also notice
these

<http://www.ip2location.com/> (which can pinpoint beyond country, down
to city)

and many others.

I did mean "country" as opposed to "language."

I want to deny access to a particular page for all visitors coming from
a particular country. Visitors from all other countries can have
access. It's a question of complying with a court order granting
suppression of information to a particular country.

I realise I can't stop determined people (who might use an anonymizing
service, for example) so I know it's not going to be 100% but I want to
do what I can.

Here is a hypothetical and fictional analog: imagine if a webmaster
wanted to avoid pissing off the Chinese authorities by denying access
to a particular news page if the visitor is coming from China. I think
if some steps are taken, the authorities will not be pissed off with
the webmaster, only with a determined surfer who tries to evade the
block.
 
A

Alan J. Flavell

Thanks very much, Jukka, I appreciate your reply.

Unfortunately, it doesn't help me and I truly hope you are a little
bit incorrect.

No, it's quite true what Jukka wrote.
I did a search and found myself here
<http://software77.net/cgi-bin/ip-country/geo-ip.pl> but I also notice
these

<http://www.ip2location.com/> (which can pinpoint beyond country, down
to city)

Well yes - in favourable cases. But there are enough cases where it
won't do what was wanted, to make it impractical for real use. It says
I'm located in London, which is wrong. I'd say giving a wrong answer
is worse than admitting that the information simply isn't available.
I want to deny access to a particular page for all visitors coming
from a particular country. Visitors from all other countries can
have access. It's a question of complying with a court order
granting suppression of information to a particular country.

That might be different! Presumably now it's not so much a question
of actually working (in the technical sense), but of doing whatever
the court says you have to do. I don't think this newsgroup is really
a good place for getting legal advice, though, which I'm certainly not
qualified to give.
I realise I can't stop determined people (who might use an
anonymizing service, for example) so I know it's not going to be
100% but I want to do what I can.

That's not the only problem - some users will fall foul of your
acess-blocking measures through no fault of their own.

A friend works for a company whose IP numbers are all in Canada,
regardless of where they are geographically.

For a while, my ISP was routing traffic via Germany, and Google was
addressing me in German as a consequence. You can imagine how happy I
would be if someone had decided to block access from all "German"
users.

And so on.
 
J

Jukka K. Korpela

Alan said:
Well yes - in favourable cases. But there are enough cases where it
won't do what was wanted, to make it impractical for real use. It says
I'm located in London, which is wrong. I'd say giving a wrong answer
is worse than admitting that the information simply isn't available.

The former of the services tells about 147.243.3.83 for example: "Country
Not Found".
Actually their FAQ warns about problems with multinational organizations.

That's more reasonable than giving wrong information, but it also raises the
question what should be done in that case, assuming that someone is forcing
you to prevent access from a particular country.
That might be different! Presumably now it's not so much a question
of actually working (in the technical sense), but of doing whatever
the court says you have to do.

I'm afraid the court order is very vague. Lawyers tend understand IT issues
even much less than IE people understand legal issues.

Anyway, denying access by the country of the _visitor_ is quite different
from denying access by the country of the _computer_. I'm pretty sure the
court didn't understand that.

What might help the OP avoid prison and bankruptcy is a _reasonable effort_
to do what the court might be guessed to have meant. (I'm not saying "best
effort", since nobody could afford best effort in a case like this.) Using
the IP to country mapping services and treating unknown country as one that
needs to be exluded might do that, when combined with .htaccess access
control by IP address. For the technicalities, the server documentation
would need to be consulted, which probably means something like
http://httpd.apache.org/docs/1.3/howto/auth.html
That means you would use deny directives, instead of trying any redirection.
You would "want" to exclude, not to send visitors to a particular page. The
denial could be accompanied with an error message (using the ErrorDocument
directive), i.e. a document that explains the situation to people who try to
access the page but are banned according to their IP. This would be in
accordance with the spirit of Internet protocols, but it could be construed
as a way of telling banned people how to avoid the banning, since to be
informative at all, you would need to reveal something about the banning
criteria. And as long as a prospective user knows that the IP is the
problem, he can circumvent the banning rather easily (though most people
would have to ask a friend to help there).

This will cost money and time, and it will exclude visitors that are not
from the country to be excluded. If my survival depended on a business where
such things need to be done, I'd try and find some other way to earn my
living. Such a court order indicates both lack of understanding how the
Internet works and willingness to control communication in a manner in which
it cannot be controlled, so who knows what they'll throw at you next week?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top