[英]What should I use .htaccess for in Zend Framework 1.9.5 application?
我已經編寫了幾個Web MVC應用程序但從未在PHP中編寫過,我正在嘗試找出使用Zend Framework v1.9.5的最佳方法。
我對.htaccess在Zend Framework 1.9.5應用程序中的作用感到困惑。 我在Zend Framework上查閱了許多教程,書籍和SO問題(但大多數是最新的v1.8),他們都討論了.htaccess文件的核心作用。 我知道.htaccess可用於支持虛擬主機,URL重寫,並允許Apache在不通過index.php的情況下提供靜態文件,但我不確定這是當前的做法還是在v1.9.5中仍然是必需的。
目前,我已經編寫了一些非常簡單的(HTML,CSS,jQuery)Zend Framework應用程序,並在測試Ubuntu Server 9.10環境中為它們創建了Apache虛擬主機。 我根本沒有使用任何.htaccess文件,應用程序似乎工作正常。
這是我到目前為止所做的:
我使用Eclipse / PDT和zf.sh工具創建了我的應用程序。 我將css,images和js目錄添加到生成'zf create project'的公共目錄中。 這些應用程序在我當地的MAMP安裝上運行良好。
在服務器上,我在/usr/local/Zend/share/ZendFramework-1.9.5中安裝了Zend Framework,並在php.ini中將/usr/local/Zend/share/ZendFramework-1.9.5/library添加到'include_path' 。
我將應用程序復制到服務器目錄/ home / myadmin / public_html / domain [12] / com。
我通過在Slicehost虛擬主機設置中概述的Apache available-sites目錄中添加條目來創建虛擬主機。 我分配DirectoryIndex = index.php和DocumentRoot = / home / myadmin / public_html / domain [12] / com / public。 兩個應用程序似乎都運行良好。
我需要使用.htaccess文件嗎? 為了什么?
*** EDIT - My Solution
基於Richard的鏈接,我將通常位於.htaccess中的重寫語句移動到我的虛擬主機定義中,現在我的應用程序不使用.htaccess文件。 我的domain1.com虛擬主機文件如下所示:
<VirtualHost *:80>
# Define admin email, server name, and any aliases
ServerAdmin webmaster@domain1.com
ServerName domain1.com
ServerAlias www.domain1.com
# Only serve files from inside this directory
DocumentRoot /home/myadmin/public_html/domain1.com/public
# Directly serve any requested files that exist in DocumentRoot;
# otherwise redirect the request to the index.php script
RewriteEngine off
<Location />
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ /index.php [NC,L]
</Location>
# Set up log file locations
LogLevel warn
ErrorLog /home/myadmin/public_html/domain1.com/data/logs/error.log
CustomLog /home/myadmin/public_html/domain1.com/data/logs/access.log combined
</VirtualHost>
.htaccess對zend框架和大多數php框架的一個主要用途是將所有請求(靜態文件除外)重定向到引導程序文件。 您不一定需要它,但您的URL最終會看起來像/index.php/controller/action而不是/ controller / action
您也可以直接將重寫規則添加到apache配置中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.