【问题标题】:How to allow to view a file in (/../)subfolder using .htaccess?如何允许使用 .htaccess 查看 (/../) 子文件夹中的文件?
【发布时间】:2017-05-24 14:12:13
【问题描述】:

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

文件夹结构:

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

root/.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>   

root/public/.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: &lt;DirectoryMatch not allowed here

【问题讨论】:

标签: .htaccess


【解决方案1】:

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

Allow from all

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

【讨论】:

  • 同样你可以在你的站点根目录.htaccess 中添加Deny from all
  • 谢谢,但它不起作用。添加允许秋季公开,给The server encountered an internal error or misconfiguration and was unable to complete your request.
  • 为什么要加allow fall?我写了Allow from all
  • 我在 code 和 quesrion 中添加了 allow from all ,只有 cmets 有错误。感谢您的关注和回复。
【解决方案2】:

如果我没记错的话,你有&lt;Files ~ "^public.*" &gt;,那就错了。

正确的应该是&lt;Files ~ ".*" &gt;,因为您已经拥有RewriteBase /public/


&lt;Files ~ "^public.*" &gt; 将只允许匹配 public.* 的文件,但作为文件名,而不是作为路径或目录。

【讨论】:

  • 谢谢,还是不行,现在报错The server encountered an internal error or misconfiguration and was unable to complete your request.
  • 查看/var/log/apache2/error.log中的错误日志
  • [2017 年 5 月 24 日星期三 17:51:19.948912] [core:alert] [pid 4892:tid 1232] [client ::1:53133] xxx/root/.htaccess:
【解决方案3】:

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

文件夹结构:

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

root/.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

使用&lt;File &gt; &lt;FileMatch &gt; &lt;Directory &gt; &lt;DirectoryMatch &gt; 会出现错误。

【讨论】:

  • 这正是我在回答中所写的。您甚至都不需要 .htaccess 中的 RewriteEngineRewriteBase
猜你喜欢
  • 2018-09-05
  • 2013-11-27
  • 2012-04-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多