【发布时间】:2009-11-24 16:11:57
【问题描述】:
我已经编写了几个 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,并将 /usr/local/Zend/share/ZendFramework-1.9.5/library 添加到 'include_path' 中php.ini.
我将应用程序复制到服务器目录 /home/myadmin/public_html/domain[12]/com。
我通过在 Apache 可用站点目录中添加条目来创建虚拟主机,如 Slicehost Virtual Host Setup 中所述。我分配 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>
【问题讨论】:
标签: php apache zend-framework