如何让Apache支持rewrite和.htaccess
前阵子因为服务器的诸多问题,放弃了旧博客空间,将数据全转移到了这儿。这样,原空间就闲置了出来,干什么用呢?想来想去,索性装了个WordPress博客玩。一来是由于WP真的很强大,另外就是因为好奇心,反正是本着学习的态度去的。您别说,WP的主题和插件资源还真是多得数不清!为了调试各式各样的主题和插件,我不得不自己搭建了一套开发环境。由于我个人电脑是Windows系统,所以也就自然而然地使用了Win+Apache+MySQL+PHP了。
不过,这样的开发环境还是使我遇到了不少问题。比如,我这两天想看看永久链接的效果,发现设定了永久链接以后,居然除了主页以外,其他的页面全变成了404。郁闷啊!什么原因呢?原来是我的Apache没有支持mod_rewrite。
怎么办?我网上google了一下,找到的“释疑文章”最多的,是《windows环境下apache rewrite配置》这一篇。而仔细研究了下,发现该文章介绍的办法只说对了一部分。按照其操作说明做了以后,并不能解决问题,尤其是其关于AddModule的那个说明,我用Test Configuration测试,发现AddModule这个指令并不正确。可能是那篇文章已过时,而我现在用的是最新版本的Apache2.2(官方下载:http://httpd.apache.org/download.cgi)所致,好在最终我还是找到了正确的方法。因此特意记录在此,希望能为后来者解决问题。
首先,查看一下你的phpinfo(),如果在apache2handler的Loaded Modules中找到了mod_rewrite那么说明你的rewrite module已经加载了。如果没有开启“mod_rewrite”,则打开您的apache安装目录“/apache/conf/”下的 httpd.conf 文件,通过Ctrl+F查找到“LoadModule rewrite_module”,将前面的"#"号删除即可。如果没有查找到,则到“LoadModule”区域,在最后一行加入“LoadModule rewrite_module modules/mod_rewrite.so”(必须独占一行),然后重启apache服务器即可。
全部设定妥当后,我又尝试了一次,咦,怎么WordPress中设置的永久链接还是无效呢?问题在这里——
<Directory "E:/www">
#
# 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.2/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks#
# 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 None#
# Controls who can get stuff from this server.
#
Order allow,deny
Allow from all</Directory>
看到我加粗套色的那行了吧?是的,那个就是AllowOverride指令,它决定了你的.htaccess是否生效,如果你在调试永久链接的时候发现不起作用,不一定都是因为mod_rewrite没有加载,还有可能是httpd.conf设置不对造成哦,如果是因为这个原因,只须把“AllowOverride None”修改为“AllowOverride All”即可。OK,Enjoy it!
本文出自:低一度,地址:http://www.diyidu.cn/post/apache_tips.html,转载须注明!

to "如何让Apache支持rewrite和.htaccess" 引用该日志!