站长论坛

标题: ZendFramework入门配置mod_rewrite和.htaccess [打印本页]

作者: superadmin    时间: 2009-7-8 13:59
标题: ZendFramework入门配置mod_rewrite和.htaccess
本帖最后由 七月十五 于 2009-5-16 13:30 编辑

这几天有些人一直问我如何配置Zend Framework,应大家的要求,我写了这个.由于自身水平有限,写得不好,还请大家凑合着吧!

1.启用Apache的mod_rewrite模块.

2.让.htaccess生效.(这点很多人没注意) 指令的生效

.htaccess文件中的配置指令作用于.htaccess文件所在的目录及其所有子目录, 但是,很重要需要记住的是,其更高级的目录也可能会有.htaccess文件, 而指令是按查找顺序依次生效,所以, 一个特定目录下的.htaccess文件中的指令可能会覆盖其更高级目录中的 .htaccess文件的指令,即, 子目录中的指令会覆盖更高级目录或者主服务器配置文件中的指令。



例如:



目录/www/htdocs/example1中的.htaccess文件有如下内容:



Options +ExecCGI



(注意: 必须设置"AllowOverride Options"以允许在.htaccess文件中使用 "Options"指令。)



在目录/www/htdocs/example1/example2中的.htaccess文件有如下内容:



Options Includes



由于第二个.htaccess文件的存在,/www/htdocs/example1/example2中 的CGI执行是不允许的,而只允许Options Includes,它完全覆盖了之前的设置。
复制代码我的做法把httpd.conf里面的"Options"指令 <Directory "D:/apche/Apache2/htdocs">



#

# Possible values for the Options directive are "None", "All",

# or any combination of:

#   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews

#

# Note that "MultiViews" must be named *explicitly* --- "Options All"

# doesn't give it to you.

#

# The Options directive is both complicated and important.  Please see

# http://httpd.apache.org/docs-2.0/mod/core.html#options

# for more information.

#

    Options FollowSymLinks

    AllowOverride All



#

# AllowOverride controls what directives may be placed in .htaccess files.

# It can be "All", "None", or any combination of the keywords:

#   Options FileInfo AuthConfig Limit

#

    AllowOverride All



#

# Controls who can get stuff from this server.

#

    Order allow,deny

    Allow from All



</Directory>
复制代码看.htaccess是否可以用 .htaccess内容



RewriteEngine on

RewriteRule !\.(js|ico|gif|jpg|png|css|swf)$ index.php

php_value include_path "./library"
复制代码注意: 这里的.htaccess在windows无法直接建立.我个人是先建立33.htaccess然后把leaftp打开.找到本地的33.htaccess,重命名位.htaccess就可以了。哈。.

5.测试下.htaccess是否可以用 打开本地的http://localhost/  随便打入http://localhost/33  看会不会转到http://localhost/ 如果不会说明你的.htaccess没有生效.

4.下载Zend Framework   http://framework.zend.com/download

(解压后把library文件夹放在网站的根目录下)


注意问题:.htaccess一定要让它生效...

补充问题:  .htaccess里面的php_value include_path 在linux下有的无法使用的。可以通过set_include_path()函数来设置(放在require_once()之前)。
如:index.php里面要这样:
set_include_path('./library');
include 'Zend';
或者你也可以直接在php.ini里面设置.




欢迎光临 站长论坛 (http://tzlink.com/bbs/) Powered by Discuz! X3.2