拒绝访问除index.html和一些技术资产之外的所有文件

我已经阅读了这个类似的问题 ,但可悲的是,这并不能解决我的问题。 公众面对我的静态页面的一部分有以下文件夹结构:

/srv/htdocs/sub.domain.com/ ├── 403.html ├── css │  ├── bootstrap.min.css │  ├── bootstrap-theme.min.css │  └── style.css ├── fonts │  ├── glyphicons-halflings-regular.eot │  ├── glyphicons-halflings-regular.svg │  ├── glyphicons-halflings-regular.ttf │  ├── glyphicons-halflings-regular.woff │  └── glyphicons-halflings-regular.woff2 ├── index.html ├── js │  ├── bootstrap.min.js │  └── jquery.min.js └── robots.txt 

还有更多的文件夹,但这些是我不想公开的内容。 我的想法是允许无条件访问cssfontsjs文件夹,并允许个人index.html403.htmlrobots.txt文件。

 <Directory "/srv/htdocs/sub.domain.com"> Order Deny,Allow Deny from All <FilesMatch "(403|index)\.html"> Allow from all </FilesMatch> <FilesMatch "robots\.txt"> Allow from all </FilesMatch> <FilesMatch "/$"> Allow from all </FilesMatch> </Directory> <DirectoryMatch "/(css|js|fonts)" > Order Allow,Deny Allow from All </DirectoryMatch> 

我试图让我的“空文件”规则"/$"的根,但是不起作用。 如果我只使用规则"""$" Apache授予访问所有文件。

当冲浪到http://sub.domain.com/收到403 Forbidden消息,而不是index.html内容。 我缺less什么规则?

如果你愿意,你可以使用mod_rewrite而不是你所拥有的:

 RewriteEngine on #if matching any of the approved URLs RewriteCond %{REQUEST_URI} ^/(css|js|fonts).* [OR] RewriteCond %{REQUEST_URI} ^/(403|index)\.html$ [OR] RewriteCond %{REQUEST_URI} ^/robots.txt$ [OR] RewriteCond %{REQUEST_URI} ^/$ #allow the request to pass through RewriteRule .* - [L] #otherwise, if the person's IP doesn't match (replace the 123 IP with the IP you want to permit) RewriteCond %{REMOTE_ADDR} !^123\.123\.123\.123$ #send 403 forbidden (ie the [F] flag) RewriteRule .* - [F,L]