General

A Guide on Using .htaccess to Password Protect Your Magento Store

Hello Magento pals,

Last time we learned How to Display programmatically created custom options in admin order details in Magento 2.

Today, we will learn an interesting topic How to Password Protect Your Magento Store With .htaccess in Magento 2, 

Introduction

Basically, there is a huge growth in increase on password guess attacks on Magento installations. Sometimes while surfing you might have noticed that you came across any website who is asking for username and password for granting permission to access the website. Mainly, this type of website is containing passwords to protect against the spammers and hackers. To overcome this problem I have came with the best solution in this article.

Reasons why do you need htaccess authentication.

  1. Google can’t index your secure website. Development server must be protected with HTTP authentication.
  2. When some developments are going on and you don’t want to let people access the website.
  3. Restricted access to website/pages/customers or private website.

Configure Guide

Step 1: Firstly, with the use FTP or Cpanel to reach to Magento 2 root folder.

Step 2: Then open the .htaccess file and add following code at top.

AuthName "User: admin. Password: admin123"

AuthUserFile /patch/to /.htpasswd

AuthType Basic

require valid-user

ErrorDocument 401 "Authorisation Required"

Step 3: Create a file with name of .htpasswd in Magento 2 root. If you want to upload password file somewhere else, you can but make sure you mention the path accordingly in above code then.

Step 4: Use this tool

https://hostingcanada.org/htpasswd-generator/
To setup username and password as given in the below image.

Step 5: Lastly open file .htpasswd now and copy paste the user and encrypted password for example 

admin:$apr1$74z9mjal$JKvdv4G7GMpIxc/8m.OPh0

Where, admin is the username and $apr1$74z9mjal$JKvdv4G7GMpIxc/8m.OPh0 is the password respectively.

Final Words

That’s it for today! By implementing the given above steps you will be able to complete the protection for your website. You can overcome the problem of attacks by spammers and hackers to your website.

Last but not least, if you found the blog interesting, don’t forget to share with your Magento pals. Feel free to Contact Us if you find any difficulty in implementing the above steps.

Happy Magento Learning!

Click to rate this post!
[Total: 4 Average: 5]
Gaurav Jain

Gaurav Jain is Co-Founder and Adobe Certified Expert-Magento Commerce Business Practitioner. Being Computer Engineer👨‍💻 and possessing Extensive Marketing skills he handles all kinds of customer Queries and his Happy😀 & Helping🙏 Nature makes customer's day Delightful. When he isn’t working, you’ll find Gaurav Reading on Books📖 or Traveling🚗. Also, he is Speaker at Magento Meetups.

Recent Posts

How to Integrate ChatGPT with Laravel Application?

In this guide, we'll explore how to integrate ChatGPT, an AI-powered chatbot, with a Laravel…

2 days ago

What are Net Sales? How to Calculate Your Net Sales?

In the world of business, understanding financial metrics is crucial for making informed decisions and…

4 days ago

Magento 2 Extensions Digest April 2024 (New Release & Updates)

Welcome to the MageComp Monthly Digest, where we bring you the latest updates, releases, and…

4 days ago

The ABCs of Geofencing: Definition, Features and Uses

In this era, businesses are always on the lookout for ways to engage with their…

5 days ago

How to Delete Product Variant in a Shopify Remix App using GraphQL Mutations?

Managing a Shopify store efficiently involves keeping your product catalog organized. This includes removing outdated…

6 days ago

6 Innovative Tools Revolutionizing E-Commerce Operations

E-commerce has transformed the way consumers shop for products and services and interact with businesses.…

1 week ago