命令允许,拒绝阻止整个网站

命令允许,拒绝阻止整个网站

我无法使文件阻止功能正常工作。如果我在 .htaccess 中使用以下语句,它会阻止我的整个网站:

order allow,deny <Files ~ ".*\.(js|JS|css|CSS|jpg|JPG|gif|GIF|png|PNG|mp4|MP4)$"> allow from all </Files>

我正在运行 apache 2.2.22 (Debian)

如果我注释掉上述几行,我就可以再次访问我的网站。如果不清楚,我试图阻止从我的网站下载除允许的文件类型之外的所有文件。

这里和其他网站上有很多关于这个一般性主题的帖子,但我已经花了 2 或 3 个小时来解决这个问题,却无法让这个问题有所改善。如果这看起来很明显,我很抱歉。

注意:AllowOverrides 肯定是打开的。我已经在所有 conf 目录和包含的目录中查找了 AllowOverrides,现在它在所有地方都已打开。在进行 conf 更改后,我重新启动了 apache2 服务。

有人能看到我做错了什么吗?

答案1

您可以使用基于环境的阻止系统来允许和拒绝访问您的网站:

SetEnvIfNoCase request_uri (js|css|jpg|gif|png|mp4|php|html)$ allowedfiles=1
Order deny,allow
Deny from all
Allow from env=allowedfiles

SetEnvIfNocase 不区分大小写,它匹配png巴布亚新几内亚

您还可以使用 mod-rewrite :

RewriteEngine on
##If the request uri doesnt end with these extensions##
RewriteCond %{REQUEST_URI} !(js|css|jpg|gif|png|mp4|php|html)$ [NC]
##forbid the request##
RewriteRule ^ - [F,L]

相关内容