apache.htaccessmod-rewriteaccess-rules

.htacess allow from local and deny all except one user agent


I have local page. All I want to access it from my phone and my computer. There is no chance to have static IP.

RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} !MyUserAgent [NC]
RewriteRule ^ - [F,L]

Order Deny,Allow
Deny from all
Allow from MYLocalIp

These codes are not working together. How can I use them together?


Solution

  • This all can be done in single rewrite rule itself:

    RewriteEngine On
    
    RewriteCond %{HTTP_USER_AGENT} !MyUserAgent [NC,OR]
    RewriteCond %{REMOTE_ADDR} !=11.22.33.44
    RewriteRule ^ - [F,L]
    

    Where 11.22.33.44 is your local IP address.