-->

Password protection for a single .htaccess rewrite

2019-08-31 03:04发布

问题:

I need a password protection for a single site. This is a seo friendly url: The default path is:

http://www.website-url.com/index.php?id_cms=xx&controller=cms

and here is the seo url:

http://www.website-url.com/content/xx-login

I have already the .htaccess and .htpasswd, but how to specify rewriting in .htaccess only for this url? I tried this:

<filesMatch "http://www.website-url.com/content/xx-login">
IndexIgnore .htaccess .htpasswd
AuthUserFile /absolut_path/.htpasswd
AuthName "Login"
AuthType Basic
require valid-user
</filesMatch>

I'm using Prestashop.

回答1:

FilesMatch doesn't work that way, you could try using SetEnvIf to bypass the Auth unless the URI is something specific (which is what I gather you are trying to do):

IndexIgnore .htaccess .htpasswd

SetEnvIfNoCase Request_URI "^/content/xx-login" SECURED

# enforce auth if SECURED
AuthType Basic
AuthName "Login"
AuthUserFile /absolut_path/.htpasswd
Require valid-user
Order allow,deny
Allow from env=!SECURED
Satisfy any