您的位置:首页 > 运维架构 > Apache

win2003 server 下 配置 apache 的rewrite

2012-06-22 15:54 225 查看
When I try to setup PHP and Apache in my notebook, I try to enable the .htaccess setting in apache's httpd.conf. After I tried for a few
hours (YES, a few hours) at my notebook and google-ing on the internet, finally I found
the complete solution.

I record the steps here so that it can help those who want to enable .htaccess and url rewriting in Apache for
Windows and also for my own reference in future.

1. Make sure you have setup apache and php correctly. Make sure that you can run php scripts without any problem.

2. Use notepad to open httpd.conf config file. Make use the line "
LoadModule rewrite_module modules/mod_rewrite.so
" is un-commented.

3. Under "
<directory XXX></directory>
" section, change the line "
AllowOverride None
" to "
AllowOverride All
".

4. Change the line "
AccessFileName .htaccess
" to "
AccessFileName htaccess
". This is because in Windows, we can't have a file with filename that starts with a dot.

5. Save the changed file and restart Apache Windows Service. You can then use the file
htaccess
to process your url rewritting.

简单翻译一下就是:

1.去掉
LoadModule rewrite_module modules/mod_rewrite.so
前的# (apache 2.2)

2.修改
<directory XXX></directory>
中的
AllowOverride
None 为
AllowOverride All


3.如果 httpd.conf (在apache的安装目录里conf文件夹) 中 有
AccessFileName .htaccess
这行 就修改为
AccessFileName htaccess
, 并把网站目录里的 .htaccess修改为 htaccess, 不需要文件后缀,因为windows不支持以 .开头的文件。如果httpd.conf里面有没有这行,在
<directory XXX></directory>
后面加上 这行
AccessFileName htaccess
就可以了。

4.保存,重启apache就可以了。然后正确编写 url rewrite的rule.

一直都在用linux下的apache,刚接触 win2003下的apache 重写,网上有很多文章,都提到了前2条,但是对第3条没有涉及,这一条也很关键。以备后用。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: