2017-05-24 34 views
0

如何允许使用.htaccess查看(/../)subfolder中的文件?如何允许使用.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 
<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 

如果我尝试查看根/公共/ 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

+0

[.htaccess可能的重复。拒绝根目录,允许特定的子文件夹。可能?](https://stackoverflow.com/questions/7649794/htaccess-deny-root-allow-specific-subfolder-possible) – matiaslauriti

回答

1

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

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


<Files ~ "^public.*" >将只允许符合public.*但作为文件名,而不是一个路径,也没有目录的文件。

+0

谢谢你,它仍然无法正常工作,现在我收到错误'遇到服务器内部错误或配置错误,无法完成您的请求。' –

+0

看看您的错误日志'/ var/log/apache2/error.log' – matiaslauriti

+0

[Wed May 24 17:51:19.948912 2017] [core:警报] [pid 4892:tid 1232] [client :: 1:53133] xxx/root/.htaccess:

2

因为你没有在任何public/.htaccess重写规则,你真的不需要任何东西比public/.htaccess此行其他:

Allow from all 

而且Files指令用于匹配文件名,只有这样它可以从不匹配包含目录的文件路径。

+0

同样,你可以在你的网站根目录下有'Deny from all'.htaccess – anubhava

+0

谢谢,但它不起作用。添加允许公开,给出'服务器遇到内部错误或配置错误,无法完成您的请求。' –

+0

为什么要添加'allow fall'?我写了'允许所有' – anubhava

0

工作组合,以允许查看在一个文件中(/../)subfolder使用。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 
Deny from all 

root/public/.htaccess

RewriteEngine On 
RewriteBase /public/ 

Options -MultiViews 
Allow from all 
#the rest of code 

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

+0

这正是我在答案中写的。你甚至不需要在两个.htaccess中都有'RewriteEngine'和'RewriteBase'这两行 – anubhava