1

我有以下 mod 重写规则:

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

基本上,这个想法是,您可以像这样访问 index.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
4

1 回答 1

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
于 2013-04-03T15:36:54.873 回答