在工作中,我们有一个ViewVC系统,该系统已从一台机器迁移到另一台机器。该版本也已升级。旧系统使用/cgi-bin/viewvc.cgi
作为其所有网址的基础,新系统使用/viewvc
。主机名保持不变。
我们有很多具有ViewVC链接的文档,我希望这些文档仍像以前一样工作。我白天是软件开发人员,所以不是apache的专家,但我认为mod_rewrite
是正确的路线。不幸的是,我似乎无法做到我想做的事。
如果没有任何更改,当我转到网址/cgi-bin/viewvc.cgi
时,我会收到404.这是我在apache日志中看到的内容:
==> /var/log/httpd/error_log <==
[Thu May 31 03:13:10 2012] [error] [client 172.16.3.52] script not found or unable to stat: /var/www/cgi-bin/viewvc.cgi
==> /var/log/httpd/access_log <==
172.16.3.52 - - [31/May/2012:03:13:10 +0100] "GET /cgi-bin/viewvc.cgi HTTP/1.1" 404 289 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.17 Safari/536.11"
当我将RewriteEngine
/ RewriteRule
条目添加到/etc/httpd/httpd.conf
时,如下所示......
<Directory "/var/www/cgi-bin">
AllowOverride None
Options None
Order allow,deny
Allow from all
RewriteEngine on
RewriteRule ^/cgi-bin/viewvc.cgi(.*) /viewvc$1
</Directory>
我得到了403.这是日志中的内容:
==> /var/log/httpd/error_log <==
[Thu May 31 03:15:35 2012] [error] [client 172.16.3.52] Options FollowSymLinks or SymLinksIfOwnerMatch is off which implies that RewriteRule directive is forbidden: /var/www/cgi-bin/viewvc.cgi
==> /var/log/httpd/access_log <==
172.16.3.52 - - [31/May/2012:03:15:35 +0100] "GET /cgi-bin/viewvc.cgi HTTP/1.1" 403 293 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.17 Safari/536.11"
如果我修改上面的选项行以包含FollowSymLinks
和SymLinksIfOwnerMatch
,我就会回到404.
==> /var/log/httpd/error_log <==
[Thu May 31 03:17:20 2012] [error] [client 172.16.3.52] script not found or unable to stat: /var/www/cgi-bin/viewvc.cgi
==> /var/log/httpd/access_log <==
172.16.3.52 - - [31/May/2012:03:17:20 +0100] "GET /cgi-bin/viewvc.cgi HTTP/1.1" 404 289 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.17 Safari/536.11"
我做错了什么?我是否有规则错误或将它放在错误的地方? mod_rewrite
他是否正确接近?
版本:如果它很重要,我在Fedora 17计算机上使用以下软件包:
答案 0 :(得分:0)
回答我自己的问题,问题是:1)模式匹配的时间段需要转义; 2)我把规则放在错误的地方。我应该把它放在顶层,而不是在cgi-bin下。
为了完成,这是我如何解决的问题:
我启用了重写日志记录,因此我可以确切地看到重写引擎正在做什么:
RewriteLog /tmp/rewrite.log
RewriteLogLevel 9
使用原始重写规则,我会记录下来:
127.0.0.1 - - [02/Jun/2012:23:43:49 +0100] [localhost/sid#b76f4018][rid#b6d4a058/initial] (2) init rewrite engine with requested uri /cgi-bin/viewcvs.cgi
127.0.0.1 - - [02/Jun/2012:23:43:49 +0100] [localhost/sid#b76f4018][rid#b6d4a058/initial] (3) applying pattern '^/cgi-bin/viewvc.cgi(.*)' to uri '/cgi-bin/viewcvs.cgi'
127.0.0.1 - - [02/Jun/2012:23:43:49 +0100] [localhost/sid#b76f4018][rid#b6d4a058/initial] (1) pass through /cgi-bin/viewcvs.cgi
当我改变规则以逃避期间时:
RewriteRule ^/cgi-bin/viewvc\.cgi(.*) /viewvc$1
我记录了这个。
192.168.1.64 - - [03/Jun/2012:00:08:53 +0100] [192.168.1.128/sid#b76ed018][rid#b6d39058/initial] (2) init rewrite engine with requested uri /cgi-bin/viewvc.cgi/
192.168.1.64 - - [03/Jun/2012:00:08:53 +0100] [192.168.1.128/sid#b76ed018][rid#b6d39058/initial] (3) applying pattern '^/cgi-bin/viewvc\.cgi(.*)' to uri '/cgi-bin/viewvc.cgi/'
192.168.1.64 - - [03/Jun/2012:00:08:53 +0100] [192.168.1.128/sid#b76ed018][rid#b6d39058/initial] (2) rewrite '/cgi-bin/viewvc.cgi/' -> '/viewvc/'
所以这是裸露的“。”这让它不匹配。但根据the documentation,这是“任何一个角色”,所以我不清楚为什么它不起作用。
rewriting guide在整个地方逃脱了它们,但没有迹象表明它是必需的或为什么,这是一种耻辱。