首页 | PHP资讯 | 技术专栏 | 资源共享 | PHP培训 | PHP职场 | 图书 | PHP ON WIN | PHP圈子 | PHPer学习大本营
返回列表 回复 发帖

[入门]配置mod_rewrite和.htaccess

[入门]配置mod_rewrite和.htaccess

本帖最后由 七月十五 于 2009-5-16 13:30 编辑

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

1.启用Apache的mod_rewrite模块.

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

  3. 例如:

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

  5. Options +ExecCGI

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

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

  8. Options Includes

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

  2. #
  3. # Possible values for the Options directive are "None", "All",
  4. # or any combination of:
  5. #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
  6. #
  7. # Note that "MultiViews" must be named *explicitly* --- "Options All"
  8. # doesn't give it to you.
  9. #
  10. # The Options directive is both complicated and important.  Please see
  11. # http://httpd.apache.org/docs-2.0/mod/core.html#options
  12. # for more information.
  13. #
  14.     Options FollowSymLinks
  15.     AllowOverride All

  16. #
  17. # AllowOverride controls what directives may be placed in .htaccess files.
  18. # It can be "All", "None", or any combination of the keywords:
  19. #   Options FileInfo AuthConfig Limit
  20. #
  21.     AllowOverride All

  22. #
  23. # Controls who can get stuff from this server.
  24. #
  25.     Order allow,deny
  26.     Allow from All

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

  2. RewriteEngine on
  3. RewriteRule !\.(js|ico|gif|jpg|png|css|swf)$ index.php
  4. 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里面设置.


本文出处:www.phpwb.com
MVMMALL首席CEO
www.mvmmall.com

请部IIS下怎以配置?

TOP

返回列表