Magento Expert Forum - Improve your Magento experience

Results 1 to 2 of 2

Protect a Directory Using .htaccess

  1. #1
    Administrator david's Avatar
    Join Date
    Nov 2012
    Thanked 42 Times in 34 Posts

    Lightbulb Protect a Directory Using .htaccess

    Protecting files on your website from unauthorized users can be very important. Even more important is the method by which you accomplish this task. You could use PHP to listen for login authorization information on each page, but that doesn't protect your images, documents, and other media, does it? That's why I've found the .htaccess method of protecting files and directories the most reliable. Oh, and it's easy too!

    The system requires two files -- the .htaccess file and .htpasswd file.

    The .htaccess Code

    AuthType Basic
    AuthName "restricted area"
    AuthUserFile /home/davidwalsh/html/protect-me-dir/.htpasswd
    require valid-user
    The above code protects a directory called "protect-me-dir" at root level. The "AuthUserFile" value is always specific to your hosting configuration. If you don't know what the value should be, do a phpinfo() and find the DOCUMENT_ROOT value.

    The .htpasswd Code

    The .htpasswd file contains the usernames and passwords of allowed users. One per line. The passwords are MD5'd for security purposes.

    To generate encrypted passwords for your .htpasswd file, you can use .htaccess password generator.

    Source: davidwalsh

    View more threads in the same category:

  2. #2
    Junior Member
    Join Date
    Sep 2018
    United Kingdom
    Thanked 2 Times in 2 Posts


    Make a record called .htaccess inside the registry you need to secret key secure.


    Make a record called .htpasswd in indistinguishable catalog from .htaccess.

    Make sure to set the authorizations on the .htaccess and .htpasswd documents.

Similar Threads

  1. Check Size of a Directory in Linux Tips
    By david in forum PHP programming
    Replies: 2
    Last Post: 22-04-2019, 07:56 AM
  2. 30 Popular .htaccess code snippets
    By david in forum Programming & Development
    Replies: 4
    Last Post: 14-12-2018, 03:04 AM
  3. How to use .htaccess to redirect www to non-www?
    By speed2x in forum PHP programming
    Replies: 2
    Last Post: 22-06-2015, 01:23 PM
  4. Could not determine temp directory, please specify a cache_dir manually
    By shunavi in forum Programming & Development
    Replies: 1
    Last Post: 19-06-2013, 01:48 PM
  5. Magento directory structure
    By rocker in forum Programming & Development
    Replies: 1
    Last Post: 27-03-2013, 02:51 PM

Tags for this Thread


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts