【问题标题】:why this configuration of mod_rewrite and .htaccess on localhost on Windows doesn't work?为什么 Windows 本地主机上的 mod_rewrite 和 .htaccess 配置不起作用?
【发布时间】:2011-07-15 22:04:57
【问题描述】:

我正在开发一个 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

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

【问题讨论】:

  • 1) 确保启用 .htaccess 文件(将AllowOverride All 放在适当的位置); 2) 请开启rewrite调试(RewriteLogLevel 9)并查看rewrite log。
  • AllowOverride All - 基本上,这就是答案。请把它作为一个新的答案,这样我就可以接受它。谢谢

标签: windows apache mod-rewrite


【解决方案1】:
  1. 确保 .htaccess 文件已启用(将 AllowOverride All 放在适当的位置)。

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

【讨论】:

    【解决方案2】:

    您在更改httpd.conf 后是否重新启动了 apache?除非您这样做,否则不需要使用新设置。

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

    【讨论】:

    • 是的,每次对这个文件进行一些更改后,我都会重新启动 Apache。我在 httpd.conf 中根本没有找到 AddModule mod_rewrite.c 这一行
    • @Piotr 如果您使用 Apache v2 或更新版本,我认为您不需要该行。
    • @Piotr 你试过这个吗:RewriteRule ^(.*).htm$ $1.php [NC]
    • @Piotr 如果你把D:\MyWeb\simple_cms\index.htm,你打电话给http://127.0.0.1/simple_cms/index.htm时可以打开它?
    猜你喜欢
    • 1970-01-01
    • 2015-03-19
    • 2016-12-30
    • 1970-01-01
    • 2014-02-16
    • 1970-01-01
    • 2011-08-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多