Password protection for a single .htaccess rewrite

二次信任 提交于 2019-12-13 06:25:51

问题


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


来源:https://stackoverflow.com/questions/21269079/password-protection-for-a-single-htaccess-rewrite

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!