Question

At work we have a ViewVC system which has been migrated from one machine to another. The version has also been upgraded. The old system used /cgi-bin/viewvc.cgi as the base of all its urls and the new system uses /viewvc. The hostname remains the same.

We have a lot of documentation which has ViewVC links and I would like those to still work as before. I'm a software developer by day so not an expert on apache but I thought that mod_rewrite would be the right route. Unfortunately I can't seem to get it to do what I want.

Without any changes, when I go to the url /cgi-bin/viewvc.cgi I get a 404. Here's what I see in the apache logs:

==> /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"

When I add the RewriteEngine/RewriteRule entries to /etc/httpd/httpd.conf as below ...

<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>

I get a 403. Here's what's in the logs:

==> /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"

If I edit the Options line above to include FollowSymLinks and SymLinksIfOwnerMatch I'm back to a 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"

What am I doing wrong? Do I have the rule wrong or have it put it in the wrong place? Is mod_rewrite even he correct approach?

Versions: In case it is important, I am on a Fedora 17 machine with the following packages:

  • httpd-2.2.22-4.fc17.x86_64
  • viewvc-1.1.13-2.fc17.noarch
  • viewvc-httpd-wsgi-1.1.13-2.fc17.noarch
Was it helpful?

Solution

To answer my own question, the problem was that 1) the period in the pattern match needed escaping and 2) I put the rule in the wrong place. I should have put it at the top level rather than under cgi-bin.


For completion, here's how I worked it out:

I turned on rewrite logging so I could see exactly what the rewrite engine was doing:

RewriteLog /tmp/rewrite.log
RewriteLogLevel 9

Using the original rewrite rule, I get this being logged:

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

When I changed the rule to escape the period:

RewriteRule ^/cgi-bin/viewvc\.cgi(.*) /viewvc$1

I got this logged.

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/'

So it was the bare "." that was making it not match. But this is "Any single character" according to the documentation, so it was unclear to me why it didn't work.

The rewriting guide escapes them all over the place, but with no indication that it is required or why, which is a shame.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top