Moeed Farooqui
Moeed Farooqui

Reputation: 3622

How to protect a specific url through htaccess

I want to add a login restriction on certain page like.

www.example.com/testing

whenever someone hit this url it should ask password, otherwise whole website should work password free.

Htaccess Code:

SetEnvIfNoCase Request_URI ^/testing-softwares SECURED

AuthName "Restricted Area"
AuthType Basic
AuthUserFile /path/to/your/.htpasswd
AuthGroupFile /
Require valid-user

Satisfy    any
Order      Allow,Deny
Allow from all
Deny from env=SECURED


# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /nrl_shareware/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /abc_shareware/index.php [L]
</IfModule>

# END WordPress

Htpasswd Code:

test:$apr1$O9AK9s5s$H0IuOqkTnB0yJ5k35kX2a1

Updated Code

SetEnvIfNoCase Request_URI ^/testing-softwares SECURED

AuthName "Restricted Area"
AuthType Basic
AuthUserFile "D:/DONT DELETE 80-261209/ABCProjects/xampp/htdocs/abc_shareware/.htpasswd"
AuthGroupFile /
Require valid-user

Satisfy    any
Order      Allow,Deny
Allow from all
Deny from env=SECURED


# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /abc_shareware/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /abc_shareware/index.php [L]
</IfModule>




# END WordPress

Upvotes: 2

Views: 2906

Answers (1)

anubhava
anubhava

Reputation: 785098

You can use it this way with mod_setenvif:

SetEnvIfNoCase Request_URI ^/testing SECURED

AuthName "Restricted Area"
AuthType Basic
AuthUserFile /path/to/your/.htpasswd
AuthGroupFile /
Require valid-user

Satisfy    any
Order      Allow,Deny
Allow from all
Deny from env=SECURED

Upvotes: 2

Related Questions