为什么Windows上localhost的mod_rewrite和.htaccess配置不起作用?

时间:2011-07-15 12:26:38

标签: windows apache mod-rewrite

我正在开发一个PHP网站,它在Apache 2.2和Windows 7上的localhost上运行。

在我的httpd.conf中,我启用了mod_rewrite模块:

LoadModule rewrite_module modules/mod_rewrite.so

我在D:\ MyWeb中有一个文档根目录,而我正在处理的网站是D:\ MyWeb \ simple_cms

出于测试目的,我已将.htaccess文件放在D:\ MyWeb \ simple_cms中,这是它的内容:

Options +FollowSymlinks

RewriteEngine on
RewriteRule ^(.*)\.htm$ $1.php [NC]

现在,调用http://127.0.0.1/simple_cms/index.htm应该“重定向”到http://127.0.0.1/simple_cms/index.php,但它会显示“404 Not Found Error”(当然index.php存在)

在access.log中有:

127.0.0.1 - - [15/Jul/2011:14:16:15 +0200] "GET /simple_cms/index.htm HTTP/1.1" 404 218

并在error.log中:

[Fri Jul 15 14:19:30 2011] [error] [client 127.0.0.1] File does not exist: D:/MyWeb/simple_cms/index.htm

为什么这不起作用?这个正则表达式无效吗?

2 个答案:

答案 0 :(得分:4)

  1. 确保启用.htaccess文件(将AllowOverride All放在适当的位置)。

  2. 如果没有 - 请启用重写调试(RewriteLogLevel 9)并检查重写日志。

答案 1 :(得分:0)

您对httpd.conf进行更改后是否重启了apache?除非您这样做,否则不会使用新设置。

你也取消注释httpd.conf中的以下行(如果存在):
AddModule mod_rewrite.c