如何允许使用.htaccess查看(/../)subfolder中的文件?

时间:2017-05-24 14:12:14

标签: .htaccess

如何使用.htaccess在(/../)子文件夹中查看文件?

文件夹结构:

root/
root/.htaccess
root/public
root/public/.htaccess
root/public/index.php
root/public/css
root/public/js

根/ htaccess的

 RewriteEngine On
 RewriteBase /
 Options -MultiViews
<FilesMatch  ".*">
  Deny from all
</FilesMatch>

#i tried to add here, public directory permission, but it does not work
#with DirectoryMatch i am getting the error The server encountered an internal error or misconfiguration and was unable to complete your request.
#without DirectoryMatch i am getting the error You don't have permission to access /type705b/public/index.php on this server.
<DirectoryMatch "/public.*">
 Allow from All
</DirectoryMatch>   

根/公共/ htaccess的

RewriteEngine On
RewriteBase /public/
Options -MultiViews
#wrong according comments <FilesMatch "public.*" >
  Allow from all
#</FilesMatch>
#the rest of htaccess below

如果我尝试查看root / public / index.php,我收到错误:Forbidden You don't have permission to access /root/public/index.php on this server.

更正后,我得到The server encountered an internal error or misconfiguration and was unable to complete your request. 上面代码的错误日志显示xxx/htdocs/root/.htaccess: <DirectoryMatch not allowed here

3 个答案:

答案 0 :(得分:2)

由于您在public/.htaccess中没有任何重写规则,因此除了此行之外,public/.htaccess中并不需要任何内容​​:

Allow from all

此外,Files指令仅用于匹配文件名,因此它永远不会匹配包含目录的文件路径。

答案 1 :(得分:1)

如果我没错,你有<Files ~ "^public.*" >,这是错的。

正确的应该是<Files ~ ".*" >,因为您已经拥有RewriteBase /public/

<Files ~ "^public.*" >仅允许与public.*匹配的文件,但作为文件名,而不是路径或目录。

答案 2 :(得分:0)

允许使用.htaccess在(/../)subfolder中查看文件的工作组合:

文件夹结构:

root/
root/.htaccess
root/public
root/public/.htaccess
root/public/index.php
root/public/css
root/public/js

根/ htaccess的

RewriteEngine On
RewriteBase /
Options -MultiViews
Deny from all

根/公共/ htaccess的

RewriteEngine On
RewriteBase /public/

Options -MultiViews
Allow from all
#the rest of code

使用<File > <FileMatch > <Directory > <DirectoryMatch >给出了错误。