0

I have been trying to add htpasswd authentication to my wordpress blog for all pages. So that when a person tries to view a page he has to be a valid-user. I tried adding the following snippet to my .htaccess file but it does nothing.

<Files *>
AuthUserFile /usr/local/apache/passwords
AuthName "Private access"
AuthType Basic
require valid-user
</Files>

Is it really possible with wordpress sites? I searched online and found people protecting wp-login.php with .htpasswd but not the other pages.

Please help.

maths
  • 1,399
  • 5
  • 23
  • 38
  • Where are you placing the `.htpasswd` and `.htaccess` files? Do you have a file at `/usr/local/apache/passwords`? – WillS Oct 29 '15 at 00:44
  • yes the passwords files is present.. and .htaccess file is where the wp setup is – maths Oct 29 '15 at 00:47
  • 1
    I just tried adding what you added to the existing `.htaccess` file in a new WordPress install and it works fine for me. – WillS Oct 29 '15 at 01:20
  • 1
    Is there no effect at all? Make sure `AllowOverride All` is allowed in your Apache configuration. I believe it is now disabled by default on some installs. – WillS Oct 29 '15 at 01:24
  • @WillS I checked my apache configuration and it was messed up as i was experimenting to make it work. I made sure AllowOverride All was there in apache config and added the above snippet to my .htaccess in wordpress setup... it works finally! thanks alot ! :) – maths Oct 29 '15 at 17:40

2 Answers2

0

Not sure I 100% understand the question but could you not just wrap the content on single.php in a is current user is logged in?

<?php
if ( is_user_logged_in() ) {
    // do content
}
?>
cody collicott
  • 261
  • 2
  • 6
0
  1. Make sure you set directory directive AllowOverride All
  2. Make sure Apache server has read permission on the passwords file
  3. Use htpasswd cli to set credentials
Scriptonomy
  • 3,975
  • 1
  • 15
  • 23