Shen
Shen

Reputation: 27

Restrict access to local address only in the server

I have multiple web application systems in the server and can be accessible through internet using 122.0.0.1 . I want to access one system only in localhost/network without internet connection using 192.0.0.0.

example: 122.0.0.0/abc 122.0.0.0/def 122.0.0.0/ghi can access through internet. but i dont want to access 122.0.0.0/abc through internet. i want to access it using 196.0.0.0/abc online through LAN.

Is this possible? then how?

Thank you.

Upvotes: 0

Views: 850

Answers (1)

Mike J
Mike J

Reputation: 425

In your .htaccess file, you can add these lines to only allow specific ip addresses:

Order Deny,Allow
Deny from all
Allow from YourIPAdress

You could also use this method, include this in your .htaccess or virtual host config file:

Mentioned here: https://stackoverflow.com/a/23325758/1993548

<IfModule mod_rewrite.c>
    RewriteEngine on

    RewriteCond %{REMOTE_ADDR} xxx\.xxx\.xxx\.xxx [OR]
    RewriteCond %{REMOTE_ADDR} xxx\.xxx\.xxx\.xxy [OR]
    RewriteCond %{REMOTE_ADDR} xxx\.xxx\.xxx\.xxz
    RewriteRule .* - [L] #do notthing

    #if we are here, the IP is not in the allowed list, redirect
    RewriteCond %{REQUEST_URI} !/maintenance.html$ [NC]
    RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif) [NC]
    RewriteRule .* /maintenance.html [R=302,L]
</IfModule>

Upvotes: 1

Related Questions