Specific URL for specific IP

Discussion in 'Apache' started by pukhtoogle, Oct 28, 2012.

  1. #1
    We have a domain environment (LAN) having ISA, DNS, Exchange, Apache installed, and the system is running on Apache. We have different modules for different user/PC like

    http://myapp/module1 --> for reception
    http://myapp/module5 --> HR department

    Now HR can access Reception module with this URL but later on they will face login screen which disallow them to login to different module, but i want to make some settings in Apache to show only module1 to reception and module5 to HR with the help of IP.

    http://myapp/module1 can only be accessed with 192.168.1.6
    http://myapp/module5 can only be accessed with 192.168.1.4
    and so on...

    Thank You
     
    pukhtoogle, Oct 28, 2012 IP
  2. pr0t0n

    pr0t0n Well-Known Member

    Messages:
    243
    Likes Received:
    10
    Best Answers:
    10
    Trophy Points:
    128
    #2
    There are several tricks you could do there. For example something like this in your .htaccess file in the main html folder:
    
    RewriteEngine On
    RewriteBase /
    
    RewriteCond %{REMOTE_ADDR} !^192\.168\.1\.6$
    RewriteCond %{REQUEST_URI} !^/module1$
    RewriteRule ^(.*)$ forbidden.html [R=302,L]
    
    RewriteCond %{REMOTE_ADDR} !^192\.168\.1\.4$
    RewriteCond %{REQUEST_URI} !^/module5$
    RewriteRule ^(.*)$ forbidden.html [R=302,L]
    
    Code (markup):
    This lines will allow access for 192.168.1.6 to module1 and 192.168.1.4 to module5, and redirect others to example page you can place in your main html folder named forbidden.html You could also just deny access and not display forbidden page by replacing this line(s):
    
    RewriteRule ^(.*)$ forbidden.html [R=302,L]
    
    Code (markup):
    with this:
    
    RewriteRule ^(.*)$ / [F]
    
    Code (markup):
    which should return 403 - forbidden message/page.
    I hope this info helps a little bit.

    Cheers!
     
    pr0t0n, Oct 28, 2012 IP