启用了Apache mod_rewrite,但无法正常工作

针对使用mod_rewrite的问题进行第二天的抗争。

系统操作系统:Windows XP HTTP服务器:Apache 2.2 httpd

耦合来自httpd.conf的相关行

LoadModule rewrite_module modules/mod_rewrite.so LoadModule proxy_module modules/mod_proxy.so DocumentRoot "N:/Web-dev/www" <Directory "/"> Options Indexes +FollowSymLinks MultiViews AllowOverride All Order allow,deny Allow from all </Directory> <Directory "N:/Web-dev/www"> Options Indexes +FollowSymLinks MultiViews AllowOverride All Order allow,deny Allow from all </Directory> 

.htaccess包含:

 RewriteEngine on RewriteRule ^alice.html$ bob.html 

PHP信息说

 Loaded Modules core mod_win32 mpm_winnt http_core mod_so mod_actions mod_alias mod_asis mod_auth_basic mod_authn_default mod_authn_file mod_authz_default mod_authz_groupfile mod_authz_host mod_authz_user mod_autoindex mod_cgi mod_dir mod_env mod_include mod_isapi mod_log_config mod_mime mod_negotiation mod_setenvif mod_rewrite mod_proxy mod_php5 

两个文件都存在,加载alice.html,它仍然加载它,在rewrite.log,它显示:

 127.0.0.1 - - [25/Apr/2011:11:01:27 +0300] [localhost/sid#7b5148][rid#2bc70b0/initial] (1) [perdir N:/Web-dev/www/] pass through N:/Web-dev/www/alice.html 

我eaven试图testing,如果它正在读取.htaccess文件,通过添加一些乱码来重写引擎命令,并且certificate:

 [Mon Apr 25 10:47:04 2011] [alert] [client 127.0.0.1] N:/Web-dev/www/.htaccess: Invalid command 'ReDELETEMEwriteEngine', perhaps misspelled or defined by a module not included in the server configuration 

但是对RewriteRule做同样的改变,就像忽略了这些一样。 我eaventesting更多 – 添加一些DELETEME之前RewriteEngine命令 – 它失败,错误,如果我以后添加任何东西,它会忽略它,就像没有错误!

我没有select,该怎么做!?

相关的问题

做更多的testing,我得到了奇怪的结果 – 在RewriteEngine命令之前添加了一些DELETEME – 它会失败,如果之后添加任何东西,它会忽略它,就像没有错误!

然后我回想一下我用正则expression式和文本分析的经验,我想知道,如果篡改CRLF会做任何好事,揭露什么是当前文件的新行符号,揭示出它们在哪里CR。 据我所知,Apache是​​基于unix的软件,我想,它可能会误解这些,所以我把它们转换成了LF的,就是这样,一切都很顺利!

注意将来 – 使用你的编辑器(EditPlus,Notepad ++等),确保你的.htaccess新行符号是多平台兼容的(CRLF),或者至less与unix兼容(LF),如果使用apache!

PS:对dublicate(在这里和stackoverflow)对不起。

既然你在模式中显式地引用了行开始(^)和行结束($),也许你只需要在你的重写规则中添加一个/来匹配请求呢?

 RewriteRule ^/alice.html$ bob.html # ^ this one 

请求http://localhost/alice.html将发送一个请求path“/alice.html”的标题,这样你的模式可能不会匹配。