Problem with .htaccess y and .htpasswd after migration from Cpanel

mosse.francisco

New member
Joined
Jul 15, 2025
Messages
4
Hi, after migrating websites from Cpanel to DirectAdmin all the websites that have protected folder started to show 500 error after writting user and password in the popup.

Important: in the control panel, in the protected folders menu, I see the protection. And the file .htpasswd exists!

Why if I see the log, I read:

[Wed Jul 16 03:34:27.102098 2025] [authn_file:error] [pid 3537264:tid 3537643] (13)Permission denied: [client 181.47.104.31:0] AH01620: Could not open password file: /home/mydomain/domains/mydomain.com/.htpasswd/public_html/protected_folder/.htpasswd

and the .htaccess call it fine

AuthType Basic
AuthName "Protegido"
AuthUserFile "/home/mydomain/domains/mydomain.com/.htpasswd/public_html/protected_folder/.htpasswd"
require valid-user

I tried deleting and re-creating the protection and it sill happens.

So I had to
1) Copy /home/mydomain/domains/mydomain.com/.htpasswd/public_html/protected_folder/.htpasswd to /home/mydomain/domains/mydomain.com/public_html/protected_folder/.htpasswd

Modiy .htaccess so it searches .htpasswd in the new location

I think that there is a bug with this

Thanks,
Francisco
 
Hello Francisco,

Probably the file /home/mydomain/domains/mydomain.com/.htpasswd/public_html/protected_folder/.htpasswd or one of its parent directories has insufficient permissions. You might try and remove the folder /home/mydomain/domains/mydomain.com/.htpasswd/ and let directadmin create it once again.
 
Yes I have finally run a custom code to fix it in all sites

Bash:
sudo find /home/ -type f -name ".htaccess" | while read htaccess; do
    old_line=$(sudo grep -i AuthUserFile "$htaccess")
    if [ -n "$old_line" ]; then
        old_passfile=$(echo "$old_line" | awk '{print $2}' | tr -d '"')
        if echo "$old_passfile" | grep -q "/.htpasswd/"; then
            folder_path=$(dirname "$htaccess")
            new_passfile="$folder_path/.htpasswd"

            echo "=== EXECUTING ==="
            echo "Detected .htaccess: $htaccess"
            echo "Actual file .htpasswd: $old_passfile"
            echo "New destination: $new_passfile"

            # Mover archivo .htpasswd
            if sudo test -f "$old_passfile"; then
                sudo mv "$old_passfile" "$new_passfile"
                echo "Moved: $old_passfile -> $new_passfile"
            else
                echo " File Not found to move: $old_passfile"
            fi

            # Reemplazar en .htaccess
            sudo sed -i "s|$old_passfile|$new_passfile|g" "$htaccess"
            echo "Updated .htaccess: $htaccess"
            echo "==================="
        else
            echo "Ignore it because it´s not in /.htpasswd/: $old_passfile"
        fi
    fi
done
 
Back
Top