开发者

How to configure an Apache rewrite-rule to redirect all requests to 404 unless explicitly allowed

开发者 https://www.devze.com 2023-03-10 12:02 出处:网络
I\'m searchin on internet sin开发者_JAVA百科ce yesterday and i couldn\'t find the answer. At least one that works for apache2.

I'm searchin on internet sin开发者_JAVA百科ce yesterday and i couldn't find the answer. At least one that works for apache2.

I just want a set of rewritemod rules that will make apache redirect everything to a 404 but allows me to explicitly override it for some files/folders.

I've tried an inclusive rule but i couldn't get it working.

Thanks.


Just try this line in your .htaccess file:

RewriteRule ^(?!(allowedFile\.html|allowedDirectory/)) - [R=404,L,NC] 

Above rule will throw 404 for everything except a file called allowedFile.html and a folder called allowedDirectory.


RewriteRule ^/protectedfolder/(.*) -  [L] /* no substitution , serve as it is for this folder*/
RewriteRule ^$ - [R=404,L] /*reject everything */
0

精彩评论

暂无评论...
验证码 换一张
取 消