2013-04-03 30 views
1

我有以下的国防部重写规则:现代重写显示私人文件访问被拒绝

RewriteCond %{DOCUMENT_ROOT}/../application/%{REQUEST_URI} -f 
RewriteRule ([\w]+\/www\/(.*)) %{DOCUMENT_ROOT}/../../application/$1 [L] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(.*)$ ./index.php/$1 

我的服务器目录布局就像这样:

/application 
--/example 
----/www 
------/test.jpg 
/www <- public root 
--/.htaccess 
--/index.php 

基本上,这个想法是,你访问索引.php像这样:

example.com/test/paths/ < would pass test/paths/ to index.php 

example.com/example/www/test.png < would pass example/www/test.png to index.php 

example.com/example/www/test.jpg < would output the contents of test.jpg 

现在前两个例子完美地工作。当我们看到最后一个会输出test.jpg(它位于非公共目录)的例子时,我得到这个错误:

您没有权限访问/ C:/ web/git/framework/application/example/www/test.jpg在这个服务器上。

我可以把这个传递给另一个公共PHP文件,然后只是做一个私人文件的file_get_contents并显示它的方式,但我最好不想派生额外的PHP进程。无论如何,我可以做我想要的东西,而不需要拒绝访问部分?

编辑

我已经通过不同的接近它解决了这个问题。我感动了整个应用程序目录复制到www目录,现在我用这个HT ACCESS文件只加载文件\ W/WWW内/ *目录

RewriteCond %{REQUEST_URI} ^/[\w]+/www/(.*)$ 
RewriteCond %{DOCUMENT_ROOT}/applications/%{REQUEST_URI} -f 
RewriteRule ([\w]+\/www\/(.*)) /applications/$1 [L] 

RewriteCond %{REQUEST_URI} !^/index.php/.* 
RewriteRule ^(.*)$ ./index.php/$1 
+1

_Why_你通过HTTP了地方的资源应该是可用的外文档根? – CBroe

+0

在我的框架中,可以有许多“应用程序”,每个应用程序中都有MVC文件和其他php文件以及存储所有资产的“www”文件夹。这个想法是一个应用程序简单的拖放和框架照顾其余的。框架文件和应用程序文件由于安全原因而未公开,但我希望“www”文件夹可公开访问 – Ozzy

+1

定义ALIAS将是当时要做的事情,但我会说 - 但请注意,这只是可能在服务器配置中,而不是通过.htaccess - http://httpd.apache.org/docs/2.2/mod/mod_alias.html#alias – CBroe

回答

1

我已经通过不同的接近它解决了这个问题。我感动了整个应用程序目录复制到www目录,现在我用这个HT ACCESS文件只加载文件\ W/WWW/*目录中

RewriteCond %{REQUEST_URI} ^/[\w]+/www/(.*)$ 
RewriteCond %{DOCUMENT_ROOT}/applications/%{REQUEST_URI} -f 
RewriteRule ([\w]+\/www\/(.*)) /applications/$1 [L] 

RewriteCond %{REQUEST_URI} !^/index.php/.* 
RewriteRule ^(.*)$ ./index.php/$1 
+1

为什么不把它作为答案发布,以便你可以接受它? – cheesemacfly

+0

两天前我无法接受我自己的答案,但我明白你的观点 – Ozzy