服务器目录读取权限

(1)我目前正在将一个项目转移到一个虚拟主机。

(2)我想将网站安装到一个子域 – 即。 sub.domain.com

(3)我已经将sub.domain.com引导到服务器根目录的/sub/public_html/sub/public_html

(4) /sub有2个目录:

 `public_html` - for the publicly traversable files & directories `resources` - for sensitive documents 

(3)我现在想要:

  (a)users to be able to visit `sub.domain.com` and traverse the contents of `public_html` (b)users NOT to be able to traverse the contents of 'resources` (b)users NOT to be able to view the DIRECT/IMMEDIATE contents of the server root 

我的问题是:

(1)可以用.htaccess来完成吗?

(2)如果是这样,怎么样?

谢谢。

编辑meant /sub/public_html instead of just /sub

显而易见的答案是将子域的服务器根改为sub/public_html而不是public_html 。 如果您不希望用户能够访问以下任何内容,请不要将其包含在服务器根目录中。 服务器端脚本仍然可以访问该目录。

也就是说,你可以在.htaccess中通过性能惩罚来做到这一点:

 RewriteEngine On RewriteRule ^public_html/ - [L] RewriteRule ^resources - [R=403,L] RewriteRule .* public_html/$0 [L,QSA]