2010-02-03 85 views
1

所有, 我的Zend框架應用程序的結構是這樣的:Zend的MVC - htaccess的重定向

billingsystem 
-application 
-design 
    --css 
     --struct.css 
    --icons 
    --styles 
    --images 
    --js 
     --common 
     --thirdparty 
-public 
    --index.php 
    --.htaccess 
-library 
    -- Zend 

我的Apache虛擬主機是這樣的:

<VirtualHost *:80> 
    ServerAdmin [email protected] 
    DocumentRoot /opt/lampp/htdocs/xampp/billingsystem 
    ServerName billingsystem 
    ErrorLog logs/billingsystem.localhost-error.log 
    CustomLog logs/billingsystem.localhost-access.log common 
    <directory /opt/lampp/htdocs/xampp/billingsystem> 
    Options Indexes FollowSymLinks 
    AllowOverride all 
    Order Deny,Allow 
    Deny from all 
    Allow from 127.0.0.1 
    </directory> 
</VirtualHost> 

我的公用文件夾在.htaccess是這樣的:

RewriteEngine on 
# The leading %{DOCUMENT_ROOT} is necessary when used in VirtualHost context 
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} -s [OR] 
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} -l [OR] 
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} -d 
RewriteRule ^.*$ - [NC,L] 

RewriteRule ^.*$ index.php [NC,L] 

如果我瀏覽到http://billingsystem,它顯示apache導演y瀏覽器的路徑。如果我去http://billingsystem/public,應用程序將在網頁上執行代碼。是否可以創建或修改.htaccess文件,以便當用戶瀏覽到http://billingsystem時,它應該將瀏覽器重定向到http://billingsystem/public並執行代碼而不是顯示目錄結構?

另外,當他試圖通過瀏覽器訪問任何文件夾時,如何將用戶重定向到「公共」目錄?

回答

1

直接回答你的問題,你可以直接放在一個.htaccessbillingsystem文件夾重寫規則:

RewriteRule ^(.*)$ /public/$1 [NC,L]

但是,您的設置應該看起來更像是以下幾點:

文件系統

billingsystem 
-application 
-design 
-public 
    --index.php 
    --.htaccess 
-library 
    -- Zend 

虛擬主機

<VirtualHost *:80> 
    ServerAdmin [email protected] 
    DocumentRoot /opt/lampp/htdocs/xampp/billingsystem/public 
    ServerName billingsystem 
    ErrorLog logs/billingsystem.localhost-error.log 
    CustomLog logs/billingsystem.localhost-access.log common 
    <directory /opt/lampp/htdocs/xampp/billingsystem/public> 
    Options Indexes FollowSymLinks 
    AllowOverride all 
    Order Deny,Allow 
    Deny from all 
    Allow from 127.0.0.1 
    </directory> 
</VirtualHost> 

的.htaccess

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

RewriteRule ^.*$ index.php [NC,L] 

現在剩下的問題是,我知道你有東西在你design目錄aparently需要在網絡訪問...可以您詳細說明了design中的目錄結構,以便我們能夠弄清楚您需要做什麼(如果有的話)以正確訪問其中包含的各種類型的文件?

+1

基本上,DocumentRoot應該被移動到公共文件夾.. – 2010-02-03 17:41:54

+0

請參閱我的文章中的目錄結構編輯。現在,我嘗試將設計文件夾移動到公用文件夾中。我的/ application/view/scripts文件夾中的header.phtml文件試圖使用/design/css/struct.css來訪問它。它不適用於我這種方式.. – Jake 2010-02-03 17:48:32

+0

您是否像我的示例中那樣從重寫規則中刪除了「%{DOCUMENT_ROOT}」?另外,如果您將瀏覽器指向'http:// www.billingsystem/design/struct.css',會發生什麼樣的錯誤? – prodigitalson 2010-02-03 17:53:54

3

我剛剛在網站上經歷過這樣的事情。我的解決方案是我需要在域上使用兩個.htaccess文件。一個在網站的根級別,另一個在public文件夾中。

所以,一個在域的根是這樣的:

<Files .htaccess> 
    order allow,deny 
    deny from all 
</Files> 

Options +FollowSymLinks 
RewriteEngine On 

#Zend Rewrite Rules 
RewriteRule ^(.*)$ /public/$1 [NC,L] 

AddHandler php5-script .php 

public文件夾我已經制定了以下規則:

<Files .htaccess> 
    order allow,deny 
    deny from all 
</Files> 

RewriteEngine On 

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

這似乎很好地工作,以通過Zend框架獲取所有內容。

希望這是有幫助的。 - liam