Basic Authentication is a quick additional layer of protection for staging, demo, or limited management directories. `.htpasswd` should be kept outside the web root if possible, using an absolute file path, and user name/password should only be sent over HTTPS.
401 Unauthorized
AuthType Basic
AuthUserFile /home/user/.htpasswd
Require valid-user
password mismatchBasic Authentication is a quick additional layer of protection for staging, demo, or limited management directories. `.htpasswd` should be kept outside the web root if possible, using an absolute file path, and user name/password should only be sent over HTTPS.
Do not expect a `.htaccess` result without reserving the Apache, LiteSpeed, Plesk proxy or NGINX-only structure.
Back up the current file with the date; Find the directive and line in the Apache/LiteSpeed error log.
Do not change redirect, rewrite, header and access rules all at the same time.
Measure the status, Location, Content-Type and redirect number with curl and check the cache layers separately.
Do not keep the password file inside the web root where anyone can download it.
Meaning: The entered user cannot be authenticated.
Possible cause: Wrong password, file path, or format.
Meaning: Apache cannot access password file.
Possible cause: Relative path or permission.
Meaning: AuthConfig override permission is disabled.
Possible cause: AllowOverride AuthConfig yok.
Meaning: Basic Auth information is not secured without TLS.
Possible cause: HTTPS is not required.
Meaning: Directory-level Basic Auth protects all endpoints.
Possible cause: WordPress and the API are on the same root.
Meaning: Load balancer monitoring URL password is required.
Possible cause: The entire site is protected.
Meaning: `-c` recreated the existing file.
Possible cause: The `-c` flag was used again when adding a new user.
Meaning: The panel manages its own password directory and rules.
Possible cause: Panel otomasyonu.
No records matching this expression were found.
htpasswd -c /home/USER/.htpasswd demoCreates a new password file and the first user; do not use on an existing file.
htpasswd /home/USER/.htpasswd yoneticiAdds a user to the existing password file or updates their password.
cut -d: -f1 /home/USER/.htpasswdLists usernames without showing their hashes.
stat -c '%a %U:%G %n' /home/USER/.htpasswd .htaccess 2>/dev/null || stat -f '%Lp %Su:%Sg %N' /home/USER/.htpasswd .htaccessShows the permissions of the password and rule files.
curl -sS -o /dev/null -w 'Without auth: %{http_code}\n' https://example.com/staging/; curl -sS -u demo:PAROLA -o /dev/null -w 'With auth: %{http_code}\n' https://example.com/staging/Compares the response with and without authentication.
apachectl -M 2>/dev/null | grep -E 'auth_basic|authn_file|authz_user'Displays the necessary modules for Basic Auth.
AuthUserFile .htpasswd
Require valid-userAuthType Basic
AuthName "Yetkili Access"
AuthUserFile /home/USER/.htpasswd
Require valid-userAuthUserFile /var/www/html/.htpasswdAuthUserFile /home/USER/.htpasswdhtpasswd -c /home/USER/.htpasswd ikincihtpasswd /home/USER/.htpasswd ikinciAuthType Basic
Require valid-userRewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://example.com%{REQUEST_URI} [R=302,L]
AuthType Basic
AuthName "Yetkili Access"
AuthUserFile /home/USER/.htpasswd
Require valid-userBasic Auth directives can be used in the context of `.htaccess` on Apache-compatible servers.
Directory Privacy and Password-Protected Directories features can manage files securely.
Protecting the entire application can block API, webhook, and payment callbacks.
No. NGINX does not read `.htaccess` files. The rule must be translated to a `server` or `location` configuration.
Usually not; Apache evaluates the `.htaccess` file on each request. However, a reload or restart is required for VirtualHost, module, or AllowOverride changes.
A dated backup of the existing file should be taken, the active document root verified, and the change tested on staging or during low-traffic periods.
In cPanel it is usually inside `public_html`, in Plesk inside `httpdocs`; addon domains and subdomains may have a different document root.
LiteSpeed supports most rules through Apache compatibility; some module and handler behaviors may differ.
Full directive and line record in Apache/LiteSpeed error log. The file should be restored according to the log instead of being deleted randomly.
Domain should not be added directly without verifying domain, document root, proxy, WordPress, and server structure. Examples should be adapted and tested.
We examine redirection, rewrite, CORS, access and 500 errors with logs in cPanel, Plesk, LiteSpeed, WordPress, custom PHP and WISECP structures.