How to protect admin login with htaccess password in magento?

Can I add htaccess password restriction for the admin login only?


5 Answers 5


As far as I know, htpasswd (password prompt by using .htaccess file) requires an actual directory and the .htaccess file to be placed there. Since there's no directory for your admin URL, I don't think you can do this with htpasswd.

  • This is wrong in every way. Firstly htpasswd based authentication (i.e. "basic" Authentication) can be defined outside of .htaccess in config files and secondly it can be defined using Location or LocationMatch directives, it is not restricted only to Directory directives.
    – BlueC
    Oct 5, 2017 at 13:05

Add below code to your root htaccess file and don't forget to change your admin url, .htpasswd file page.

<Files "admin">
        AuthName "Cron auth"
        AuthUserFile E:\wamp\www\magento\.htpasswd
        AuthType basic
        Require valid-user

Create .htpasswd file in your root folder and add below username and password (set default username:admin and password: admin123)


Please let me know if you still facing any issue.


I would take a good read of the following result I just found by Googling your query, specifically 4. Use a custom admin path and 10. Restrict admin access to only approved IP addresses: http://addoa.com/blog/ten-tips-keeping-your-magento-store-secure


So if you are doing this for "security" reasons I would suggest that secure passwords and possibly changing the admin url would be enough.

To change the admin url simply update app/etc/local.xml and change the following section.


I just had to do this and I used the Location tag in apache:

<Location /admin>
           Options FollowSymLinks Indexes SymLinksIfOwnerMatch
           AuthType Basic
           AuthName "Restricted Files"
           # (Following line optional)
           AuthBasicProvider file
           AuthUserFile /home/public_html/.htauth
           Require user admin

use the command: htpasswd -c /home/public_html/.htauth admin to create the htauth. All worked as expected.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.