Search code examples
apache.htaccess.htpasswd

How to config htpasswd with htaccess


i want to make some pages password protected using .htpasswd

How can i do it ??

# Do the regex check against the URI here, if match, set the "require_auth" var
SetEnvIf Request_URI ^/product-category/ require_auth=true

# Auth stuff
AuthUserFile /home1/thetimh6/public_html/htpasswd
AuthName "Password Protected"
AuthType Basic

# Setup a deny/allow
Order Deny,Allow
# Deny from everyone
Deny from all
# except if either of these are satisfied
Satisfy any
# 1. a valid authenticated user
Require valid-user
# or 2. the "require_auth" var is NOT set
Allow from env=!require_auth

I am try it in my htaccess file but it is showing me

500 Server Error


Solution

  • Put the following code in .htaccess in public_html

    AuthType Basic
    AuthName "Password Protected Area"
    AuthUserFile /path/to/.htpasswd
    Require valid-user
    

    Then create a .htpasswd, but put it OUTSIDE public_html

    So the /path/to/.htpasswd is pointing to that location