如果能给某一类后缀的都开放权限的话更好了

非常简单的要求。
在网站中用.htaccess对管理目录进行了加密。但是由于某些原因,部分文件需要不输入密码直接访问。
前提,不能移动文件,只能修改.htaccess来达到要求。
当然,由于只是部分文件,数量很少,所以即使是需要确定的文件名也是可以接受的。

holdtom
浏览 79回答 1
1回答

慕莱坞森

既然你是希望一类后缀开放的话,那实现起来就容易多了,比如只希望 .txt可以被访问<filesMatch&nbsp;"(?<!\.txt)$">&nbsp;&nbsp;#hint:&nbsp;pcre&nbsp;look&nbsp;behind &nbsp;&nbsp;&nbsp;&nbsp;AuthUserFile&nbsp;/home/felix021/wwwroot/test/.htpasswd &nbsp;&nbsp;&nbsp;&nbsp;AuthName&nbsp;"Secret&nbsp;Stuff"&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;AuthType&nbsp;Basic &nbsp;&nbsp;&nbsp;&nbsp;require&nbsp;valid-user&nbsp;&nbsp;&nbsp; </filesMatch>下面是之前想到的比较罗嗦的做法。首先执行这个命令获得所有的文件扩展名:find -type f -exec basename {} \; | cut -d. -f2 | sort | uniq比如输出jpgjstxtphppng比如希望txt不需要密码,其他都需要,然后修改.htaccess:<filesMatch&nbsp;"\.(jpg|js|php|png)$">&nbsp;&nbsp;#这里不写txt &nbsp;&nbsp;&nbsp;&nbsp;AuthUserFile&nbsp;/home/felix021/wwwroot/test/.htpasswd &nbsp;&nbsp;&nbsp;&nbsp;AuthName&nbsp;"Secret&nbsp;Stuff"&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;AuthType&nbsp;Basic &nbsp;&nbsp;&nbsp;&nbsp;require&nbsp;valid-user&nbsp;&nbsp;&nbsp; </filesMatch>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

MySQL