You are invited to Log in or Register a free Frihost Account!

.htaccess -- redirecting an I.P. range

I was curious if it was possible (via the .htaccess file) to redirect visitors with an I.P. in a certain range to a login page.

Right now, the situation is that certain people from the school administration are/have reading/read some pages on my blog, and judged/fined me based on it. I had no chance to argue my side, so I would like to prevent school computers (in the very least) from viewing a certain subdomain without first logging in to confirm their friendship/loyalty. I would do this with PHP, but then I think I may have to add each code snippet to each page, correct? Frankly, I'm too lazy to go through each and every page in that subdomain to add a bit of code, making sure it doesn't interfere with any other PHP snippet.

So, is this possible? I know there's a "Deny" command or something alike, in which I would then enter the I.P. range, leaving out the last portion (which is what I want). I'm curious if there's something in which I could redirect these people instead of just blocking them altogether. Thanks in advance!
You should actually be able to write a single PHP script and have Apache/PHP auto-prepend it to all your PHP files, by adding this to .htaccess:

php_value auto_prepend_file redirectbyip.php

redirectbyip.php is obviously your special redirection script Wink You may need to give the full server path to the file or place a new .htaccess like that in each directory, in order to have it work on all PHP files.

It'll work as if you had <?php include "redirectbyip.php" ?> at the top of every page on your site.
I may have to use that in the future, because I would like to eventually make sure that a certain I.P. range logs in, to insure they aren't someone that shouldn't be on my site. Wink

But I'm not that far along yet, and I found this script instead: wrote:
To redirect, you are going to need to have to use the Apache rewrite_module

RewriteEngine On
RewriteCond %{REMOTE_ADDR} ^123\.45\.6\.$
RewriteRule .* [R,L]

Will redirect the block 123.15.6.* to If they have a limited block, lets say through

RewriteCond %{REMOTE_ADDR} ^123\.45\.6\.(2[5-9]|3[0-9]|4[0-6])$
RewriteRule .* [R,L]

I'm curious, though, if DirectAdmin creates a log file of any sort? I remember that cPanel does, or at least is able to show you the past 300 people that visited the site. I'd like something of the same, but only because I forgot the exact I.P.'s that I'm trying to remove. It's no biggie, just something that if I'm not seeing, I would like to find. (unless it just doesn't exist on server 2)
Related topics
Reply to topic    Frihost Forum Index -> Scripting -> Others

© 2005-2011 Frihost, forums powered by phpBB.