If you have installed WordPress to the public_html directory and enabled permalinks, you will be unable to password protect a subdirectory even with an .htaccess file. This article will help you password protect a directory and reset the permalinks afterwards.
Note:Â It is always a good policy to back up your site before you make any changes you wish to revert from later.
Edit Your .htaccess File
- Using cPanel's File Manager, edit the .htaccess file that is in your WordPress home folder (in this case, it is likely that is your public_html directory).
- Remove from your .htaccess file the line of code that has been bolded:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress - Replace that line of code with this new one:
RewriteRule ./ /index.php [L]
It 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 - Save the changes.
Resetting Permalinks
- In the WordPress Dashboard, select "Settings", and then "Permalinks". Copy the current structure.
- Click "Default".
- Select "Save Settings".
- Change the setting back to the original structure you copied in step 1.
- Click "Save Settings".
Â