CGI to transparently translate gitweb to cgit

Konstantin Ryabitsev mricon at
Wed Jun 17 20:47:24 CEST 2015

Hello, all:

Peter Anvin wrote a CGI to transition from gitweb to cgit. I was
wondering if it makes sense to incorporate it into cgit as part of contrib?

At least hopefully this will come in handy for someone so they don't
have to create terrible monstrosities with rewrite rules (like I did for


-------- Forwarded Message --------
Subject: Re: Migrating from gitweb to cgit
Date: Tue, 16 Jun 2015 12:52:09 -0700
From: H. Peter Anvin <hpa at>
To: Konstantin Ryabitsev <mricon at>

On 06/12/2015 05:26 AM, Konstantin Ryabitsev wrote:
> On 11/06/15 07:16 PM, H. Peter Anvin wrote:
>> Cool.  I ran into a set of transformation rules on the web earlier and
>> hacked up a CGI script (as I just don't trust RewriteEngine to do this
>> stuff sanely.)
>> This is the latest version of it:
> Forgot to ask -- how does it look like on the Apache side of things? I
> guess it ends up being a rewrite on the Apache side, which issues a
> redirect?

This is a bit more complicated than it otherwise would be, because I
explicitly wanted to avoid "gitweb" or "cgit" in URLs for whatever
reason, so the same namespace now contains legacy gitweb, cgit, and
http-cloning URLs.

Otherwise I wouldn't have had to use the rewriteengine at all and could
have gotten away with aliases.

<VirtualHost *:80>
DocumentRoot /var/lib/git
ErrorLog /var/log/httpd/git/error_log
CustomLog /var/log/httpd/git/access_log combined
RedirectPermanent /var/lib/git /
RedirectPermanent /pub/git /

SetEnv GIT_PROJECT_ROOT /var/lib/git

RewriteEngine on

Alias /cgit-data /usr/share/cgit
ScriptAlias /cgit /var/www/cgi-bin/cgit
ScriptAlias /robots.txt "/var/www/cgi-bin/robots.cgi"

RewriteCond "%{QUERY_STRING}" "^.*p=.*$"
RewriteRule ^/+$ /var/www/cgi-bin/gitweb2cgit.cgi [H=cgi-script]

ScriptAliasMatch ^/+$ /var/www/cgi-bin/cgit

ScriptAliasMatch ^/gitweb.cgi/*$ /var/www/cgi-bin/gitweb2cgit.cgi

AliasMatch ^/(.*/objects/[0-9a-f]{2}/[0-9a-f]{38})$
AliasMatch ^/(.*/objects/pack/pack-[0-9a-f]{40}.(pack|idx))$
ScriptAliasMatch \
        "(?x)^/(.*/(HEAD | \
                        info/refs | \
                        objects/info/[^/]+ | \
                        git-upload-pack))$" \
ScriptAliasMatch ^/+(.*)$ /var/www/cgi-bin/cgit/$1

Konstantin Ryabitsev
Linux Foundation Collab Projects
Montréal, Québec

More information about the CGit mailing list