In some cases, you might need to password protect a certain file(s). You can do just that by following the instructions below.

  1. Create a file named .htpasswd and place it above your root directory, so visitors can’t access it. Example of the root directory pathway: /home/cpanelusername/.htpasswd Create an encrypted password for the file.
  2. Right-click on the .htpasswd file and select the Code Edit option.
  3. In the popup that appears, click the Edit button.
  4. Place the generated .htpasswd information into the .htpasswd file.
  5. Click on the Save Changes button.
  6. Click on the Close button.
  7. Navigate to the directory where the file(s) that you would like to password protect lie.
  8. If an .htaccess file does not exist in the directory already, create one. (double-check your settings in the right corner that hidden files are on!)
  9. Right click on the .htaccess file and select the Code Edit option.

10. Insert the following code into the .htaccess file:

<FilesMatch “examplefile.extension”>
AuthName “Member Only”
AuthType Basic
AuthUserFile /home/cpanelusername/.htpasswd
require valid-user
</FilesMatch>

11. Be sure to replace example file.extension with your file’s actual name and replace cpanelusername with your actual cPanel username.

12. Click on the Save Changes button.

13. Click on the Close button.

 

For multiple files:

<FilesMatch “*.html”>

<FilesMatch “file.*”>

<FilesMatch “*.*”>

If you’re using WordPress and your installation is in your public_html folder, with permalinks, you’ll run into some issues. Below you’ll find the process to fix this.

NOTE: you should always have a website backup in case of a mishap

1. Edit the .htaccess file in your WordPress home folder (public_html) and remove the line  of code shown in bold below:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

2. Replace that line with this new line:

RewriteRule ./ /index.php [L]

3. The final code snippet will look like this:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ./ /index.php [L]
</IfModule>
# END WordPress

4. Save your changes

Now here’s for Resetting your Permalinks if needed.

  1. From the left-hand navigation menu in WordPress, click Settings > Permalinks. Note the current setting.
  2. Change the settings back to the previous configuration.
  3. Click > Save Settings.