Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am wanting to restrict access to a website to people inside of my network. If someone from outside hits the site they will be redirected to another page.

How do I configure these two different actions based on IP address?

share|improve this question

4 Answers 4

up vote 1 down vote accepted

Since you don't want to just prevent page loads from the external networks, but want to send them to a different page, you will need to use mod_rewrite. Assuming your local net is 192.168.1.0/24:

RewriteEngine On
RewriteCond %{REMOTE_ADDR} !^192\.168\.1
RewriteCond !^/foreigners/page
RewriteRule .* /foreigners/page [R,L]

You don't actually need to restrict the page, because the rewrite rules will ensure that the foreigners never see the page.

Note, this is not completely tested, but should get you down the path you want.

share|improve this answer

The restriction is done as follows:

<Directory /var/www/your-root-folder/>
        Options Indexes FollowSymLinks Multiviews
        AllowOverride All

        Order Deny,Allow
        Deny from all
        # Allow only from LAN subnet
        Allow from 192.168.1.0/255.255.255.0
</Directory>

Then, if you want an automatic redirection for users outside of your local subnet, you'll want to modify the default handling of "403 Forbidden". My example redirects to "index.php".

ErrorDocument 403 /index.php
share|improve this answer
    
This won't redirect foreigners to a different page, which is what the poster wants. –  Rudedog Dec 8 '09 at 16:41
    
Putting up a custom 403 for foreigners will work just fine, unless you also have other protected pages (say with passwords) that shouldn't display the foreigners' 403. –  Rudedog Dec 8 '09 at 16:54
    
Using ErrorDocument to showing a different page might be an ok solution, or it might not. Depending on the content of the redirected page an 403 respons may or may not be suitable. –  andol Dec 8 '09 at 17:05
    
In addition, since you're redirecting to another page inside the document root, the client won't be able to see the 403 page since it's still protected by the IP address restrictions. –  Rudedog Dec 8 '09 at 17:07

try this

order deny, allow

deny from all

allow from 192.168

share|improve this answer
    
This won't redirect foreigners to a different page, which is what the poster wants. –  Rudedog Dec 8 '09 at 16:42

Here is what finally worked! Thanks for everyone's help getting me close.

RewriteEngine On
RewriteCond %{REMOTE_ADDR} !^10\.5
RewriteCond %{REQUEST_URI} !^visitor\.php
RewriteRule .* visitor.php
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.