2012-03-21 44 views
0
Zend框架

你好,我有以下文件结构:国防部重写与2个公用文件夹

/public_html(docroot) 
    - /public 
     /css 
     /js 
     index.php 
    - /application 
    - /library 

注:我不能改变这个结构。我想要的:对文件的所有请求都应该打开公用文件夹中的文件,所有其他请求都应该转到index.php。目前,我有下一次的.htaccess中的public_html:

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} -s [OR] 
RewriteCond %{REQUEST_FILENAME} -l [OR] 
RewriteCond %{REQUEST_FILENAME} -d 
RewriteRule ^.*$ - [NC,L] 
RewriteRule ^.*$ index.php [NC,L] 

但它的工作原理只是http://hostname/public。如何在没有public的情况下工作?谢谢。

+0

你可以最后重写规则更改为'重写规则^ * $ /public/index.php [NC,L]'。我不确定前面的/,所以如果它不工作,请尝试省略它。 – dbrumann 2012-03-21 10:10:30

+0

它不起作用。请参阅下面的答案。 – pltvs 2012-03-21 10:15:57

+0

为什么不能将DocumentRoot设置为'public_html'?通过这种方式,'public_html'中的所有文件都是公共的并且按原样提供,并且您的'application','library'和其他文件夹被隐藏,为您提供更高的安全性。 – 2012-03-21 14:01:43

回答

1

我已经找到了答案:

RewriteEngine On 
RewriteCond %{REQUEST_URI} !public/ 
RewriteRule (.*) /public/$1 [L] 
RewriteCond %{REQUEST_FILENAME} -s [OR] 
RewriteCond %{REQUEST_FILENAME} -l [OR] 
RewriteCond %{REQUEST_FILENAME} -d 
RewriteRule ^.*$ - [NC,L] 
RewriteRule ^.*$ index.php [NC,L]