拒绝所有目录访问,但允许特定目录访问+如果需要,添加特定子文件夹

时间:2019-05-18 20:59:53

标签: .htaccess

RewriteCond触发不需要触发的RewriteRule。默认情况下,所有文件都应被禁止。

http://example.com/inc/image.png - Allowed
http://example.com/app/assets/image.png - Forbidden (Need to be allowed)
RewriteEngine On

RewriteCond %{REQUEST_URI} !^/(inc|[a-z]+/(assets|values))/
RewriteRule ^(.*)$ - [F,L]

RewriteCond %{REQUEST_URI} ^/[a-z]+/(assets|values)/ 
RewriteRule ^(.*)$ /projects/$1 [L]

仅允许dir / inc / ...和/ app / assets或values /...。 / app /不是静态的。请求网址example.com/app/assets / ...已重写为example.com/projects/app/assets /

0 个答案:

没有答案