Restrict / Block Directory Based on IP Address

前端 未结 1 719
北恋
北恋 2020-12-21 07:20

Trying to block directory access from everyone except 1 IP address. This .htaccess code blocks access but it blocks access to everything including images, css, etc. What d

相关标签:
1条回答
  • 2020-12-21 07:52

    Better way is to do this in your .conf file:

    <Directory /hidedirectory>
     options -Indexes
     Order Deny,Allow
     Deny from all
     Allow from XX.XXX.XX.XXX
    </Directory> 
    

    This will deny everythig like your rewrite rules. But since you want to allow access to images/css etc...

    RewriteCond %{REMOTE_ADDR} !^XX\.XXX\.XX\.XXX$
    RewriteCond %{REQUEST_URI} !\.(?:jpe?g|png|gif|css)$ [NC]
    RewriteRule ^hidedirectory(.*)$ http://site.com/ [R,L]
    

    Add any other extensions into (?:jpe?g|png|gif|css) suffixed by a |(or).

    0 讨论(0)
提交回复
热议问题