Welcome Guest, Not a member yet? Register   Sign In
password protected a specific url with htpasswd in codeigniter 3.x
#1

(This post was last modified: 11-11-2022, 03:32 AM by SnowranCruzick.)

I'm trying to password protect a specific url mydomain.com/admin in codeigniter 3.x with .htaccess and .htpasswd files. but I have a weird problem with the prompt! when it appears on the screen, normally I've to type correct username and password and hit the sign in button and the page have to be loaded! but!!!!! Either I click on cancel button or twice click on OK button in a row, the page loads and echatspin echatrandom shows everything.(it has to show 401 or 403 error code),

.htaccess code is here:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
RewriteRule ^([^.]+)\.html$ $1.php [L]



SetEnvIf Request_URI .*/admin/login$ require_auth=true
AuthUserFile /home2/ashkanr1/public_html/test/.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
The first part is mine but I found the second part here

update: I tried this code on my windows machine by wamp server and it's working on it:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
RewriteRule ^([^.]+)\.html$ $1.php [L]



SetEnvIf Request_URI .*/admin/login$ require_auth=true
AuthUserFile c:wamp64/www/test/.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
update2: I'm using a host not a dedicated server. Can it be an issue?
update2: I'm using a host not a dedicated server. Can it be an issue?
Reply
#2

What's happening that you don't like?
Reply
#3

Please Read:

.htaccess Tips & Tricks - 18. .htaccess protection
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB