Redirecting based on IP Address?

Soldato
Joined
18 Oct 2002
Posts
2,734
Location
Nr Colchester, Essex
Hi,

I have a little project I am working on where I need to be able to direct users coming from various IP address ranges to different folders on a webserver.

For example MrA using a PC on IP 10.10.0.xxx needs to be redirected to see the contents of FolderA (some RDP files) and MrB using a PC on 10.20.0.xxx needs to see the contents of FolderB

Is this actually possible? I know you can find out the IP address of the machine, but can you redirect based on it?

Any help much appreciated :)
 
Are the visitors visiting a single page?

You could do this through .htaccess, which is probably the easiest way too depending on how many IP's you need to catch. Each range will need a different rule and place to redirect to.

The .htaccess file would sit in the root of say www.doufos.com/start/ and just forward whoever visits that to where you specified in the .htaccess.

.htaccess works on Apache servers and can also be used on IIS with ISAPI_rewrite.

The code you will use will look something like this:
RewriteCond %{REMOTE_ADDR} ^123\.123\.123\.
RewriteRule ^index\.html$ special.page.html [R=301,L]

That would catch everyone in range 123.123.123.* who visits index.html at the same location of the htaccess file and redirect them to the special.page.html, but you could specify a complete url.
 
Last edited:
Yes, it would be a single page. A PC will be setup to goto a page on the our Intranet (running on IIS), and there will be maybe 10-20 different catches and one cover all for the rest. Each will have a folder related to it.

Thanks for the pointers.
 
Cool, well that should sort you out fine. We bought http://www.helicontech.com/isapi_rewrite/ to be able to use htaccess on our IIS server.

There is a lite version, but it has some limitations: http://www.helicontech.com/isapi_rewrite/doc/litever.htm

You may be able to get away with the lite version if it is just a single entry page, but if you ever want to have more than one htaccess.. say another service that could use it.. youll have to upgrade. The lite version only gives you one global htaccess file.
 
Back
Top Bottom