Skip to content

Instantly share code, notes, and snippets.

@MogulChris
Last active August 18, 2020 05:00
Show Gist options
  • Save MogulChris/9c75cb53f31a2e236f60764e87067fd6 to your computer and use it in GitHub Desktop.
Save MogulChris/9c75cb53f31a2e236f60764e87067fd6 to your computer and use it in GitHub Desktop.
Password protect a CodeIgniter subdirectory using .htpasswd, avoid 404 errors
#Using CPanel to password protect a CodeIgniter subdirectory, and getting a 404 error when trying to access the subdirectory? I got u fam.
# This goes in the .htaccess file in the directory you wish to protect
#The critical line is ErrorDocument 401 "Authorisation Required"
#----------------------------------------------------------------cp:ppd
# Section managed by cPanel: Password Protected Directories -cp:ppd
# - Do not edit this section of the htaccess file! -cp:ppd
#----------------------------------------------------------------cp:ppd
AuthType Basic
AuthName "My extremely secret directory"
AuthUserFile "/path/to/.htpasswd"
Require valid-user
#----------------------------------------------------------------cp:ppd
# End section managed by cPanel: Password Protected Directories -cp:ppd
#----------------------------------------------------------------cp:ppd
#Fixes your 404 issue
ErrorDocument 401 "Authorisation Required"
@MogulChris
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment