我试图让mod_rewrite规则工作在Debian Lenny上的Apache 2.2下。 为了让它工作,我把规则放在/etc/apache2/mods-enabled/rewrite.load中:
RewriteEngine On RewriteRule http-poll/ http://jabberserver:5280/http-poll [P] RewriteLog "/tmp/rewrite.log" RewriteLogLevel 3
但是,当我重新启动Apache后使用浏览器去http:// localhost / http-poll时,我得到404错误。 Error.log有:
[Wed Jun 30 15:22:53 2010] [error] [client 127.0.0.1] File does not exist: /var/www/http-poll
“/tmp/rewrite.log”是空的。
我已经启用模块(包括mod_rewrite)(a2enmod重写代理proxy_http)
我注意到,在你的重写规则中,匹配模式以斜线结束,但是你访问的URL没有。 尝试从RewriteRule
中的http-poll/
删除斜杠,看看是否能够正常工作。
我认为你需要同时指定绝对path,并确保该模式在本地path的开始:
RewriteRule ^ / http-poll / http:// jabberserver:5280 / http-poll / [P]
因为否则重写规则将再次应用,如果相同的Apache conf文件解释代理。
此外,如果您想在/ http-poll /下redirectURL,则应指定正则expression式replace:
RewriteRule ^ / http-poll /(.*)http:// jabberserver:5280 / http-poll / $ 1 [P]
而且,是的,这绝对是一个服务器故障。
其他答案都没有解释为什么你的重写日志是空的。
这里是我的猜测:除非你包含指令“RewriteOptions Inherit”,否则全局重写指令将不会被VirtualHost指令inheritance(这与其他许多Apacheconfiguration工作是不一致的)。
除了打开inheritance选项之外,还可以在正在testing的虚拟主机中重复相关的Rewrite指令。
其他地方的build议检查您的“LoadModule”行是不相关的。 如果丢失了,你的configuration很可能会被破坏,你会得到这样的错误:
“无效的命令”RewriteEngine“,可能拼错或由未包含在服务器configuration中的模块定义”
如果你将所有的Rewrite指令包装在“IfModule”块中,那么这个例外就是这样,所以当模块丢失时它们就会消失。
不应该mod_rewrite.load只包含这样的行吗?
LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so
无论如何,如果我把重写规则放在一个服务器configuration( <VirtualHost>
)中,但是如果它们在mod_rewrite.load(Ubuntu 8.04,Apache 2.2.8)中,那么它就可以工作。 如果您不使用虚拟主机,请尝试将它们放入文档根<Directory>
的<Directory>
部分。