2012-03-21 45 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]