Web Server

Protect file using .htaccess

This post is about to explain the use of .htaccess for protecting any file on your server.

Earlier I have explained the use of htaccess file to protect the .htaccess file.

Here is the code which shows the trick to protect the file using .htaccess file.

Protect File using .htaccess

[cc lang=”apache”]
# protect file

order allow,deny
deny from all

[/cc]

Enable access for particular user

[cc lang=”apache”]
# protect file

order allow,deny
deny from all
allow from 1.2.3.4
allow from 45.85.245.105

[/cc]

So above code will enable access from 1.2.3.4 and 45.85.245.105 only.

Shares:
  • killahbeez
    killahbeez
    February 10, 2012 at 12:58 pm

    order allow,deny
    deny from all
    allow from 1.2.3.4
    allow from 45.85.245.105

    This will deny all access, not allowing those any of following IPs, because of the order.

    Reply
    • Howard Lee Harkness
      Howard Lee Harkness
      December 20, 2019 at 2:55 pm

      This is what I use in my wp-admin page:

      Order Deny,Allow
      Deny from All
      Allow from xxx.xxx.xxx.

      I have a similar guard on just my wp-login.php file using:


      Order Deny,Allow
      Deny from All
      Allow from xxx.xxx.xxx.

      This keeps people outside of my area from getting to my WP login page
      …except that somehow, a brute-force login attempt is managing to bypass that, and set off the threshold limit notices from Limit Login Attempts. Which I find a bit scary. How is it possible to bypass .htaccess?

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *