Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To require users to be logged in before they can access the root folders in WordPress, you can use the following steps:

  1. Open your WordPress site's root folder in a file manager or FTP client.

  2. Create a new file named .htaccess if it doesn't already exist.

  3. Add the following lines to the top of the .htaccess file:

# Prevent access to directories
Options All -Indexes

# Require user authentication
AuthType Basic
AuthName "Restricted Area"
AuthUserFile /path/to/your/.htpasswd
Require valid-user
  1. Replace the "/path/to/your/.htpasswd" with the absolute path to the .htpasswd file. Create this file if it doesn't already exist.

  2. Save the .htaccess file.

  3. Create a new user in WordPress by going to Users > Add New. Use a strong username and password.

  4. Generate a .htpasswd file that will be used to authenticate users. You can use an online tool, or you can generate the file from the command line using this command:

htpasswd -c /path/to/your/.htpasswd username
  1. Replace "/path/to/your/.htpasswd" with the absolute path to the .htpasswd file, and "username" with the username you created in step 6.

  2. Save the .htpasswd file.

Now, when someone attempts to access the root folders in WordPress, they will be prompted to enter their username and password before they can proceed. Only authenticated users will be able to access the folders.